prasule/lib/api/category.dart
Matyáš Caras 238caf9203
fix: make edit_categories actually edit categories
Also make sure home loads the wallet again after exiting settings. Also removed 'type' from Category, because I don't know what it was supposed to do there.
2023-12-31 12:41:10 +01:00

52 lines
1.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
part 'category.g.dart';
@JsonSerializable()
/// Represents a category in a user's wallet
class WalletCategory {
/// Represents a category in a user's wallet
WalletCategory({
required this.name,
required this.id,
required this.icon,
});
/// Connects generated fromJson method
factory WalletCategory.fromJson(Map<String, dynamic> json) =>
_$WalletCategoryFromJson(json);
/// User-defined name
String name;
/// Unique identificator of the category
final int id;
/// Selected Icon for the category
@JsonKey(fromJson: _iconDataFromJson, toJson: _iconDataToJson)
IconData icon;
/// Connects generated toJson method
Map<String, dynamic> toJson() => _$WalletCategoryToJson(this);
@override
String toString() {
return name;
}
}
Map<String, dynamic> _iconDataToJson(IconData icon) =>
{'codepoint': icon.codePoint, 'family': icon.fontFamily};
IconData _iconDataFromJson(Map<String, dynamic> data) =>
IconData(data['codepoint'] as int, fontFamily: data['family'] as String?);
/// Type of entry, either expense or income
enum EntryType {
/// Expense
expense,
/// Income
income
}