prasule/lib/api/category.dart

58 lines
1.4 KiB
Dart
Raw Normal View History

2023-09-08 11:50:21 +02:00
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.type,
required this.id,
required this.icon,
});
2023-09-08 11:50:21 +02:00
/// Connect the generated [_$WalletEntry] function to the `fromJson`
/// factory.
factory WalletCategory.fromJson(Map<String, dynamic> json) =>
_$WalletCategoryFromJson(json);
/// Expense or income
final EntryType type;
/// 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;
2023-09-08 11:50:21 +02:00
/// Connect the generated [_$PersonToJson] function to the `toJson` method.
Map<String, dynamic> toJson() => _$WalletCategoryToJson(this);
2023-09-14 19:44:34 +02:00
@override
String toString() {
return name;
}
2023-09-08 11:50:21 +02:00
}
Map<String, dynamic> _iconDataToJson(IconData icon) =>
{'codepoint': icon.codePoint, 'family': icon.fontFamily};
2023-09-08 11:50:21 +02:00
IconData _iconDataFromJson(Map<String, dynamic> data) =>
IconData(data['codepoint'] as int, fontFamily: data['family'] as String?);
2023-09-08 11:50:21 +02:00
/// Type of entry, either expense or income
enum EntryType {
/// Expense
expense,
/// Income
income
}