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, }); /// Connect the generated [_$WalletEntry] function to the `fromJson` /// factory. factory WalletCategory.fromJson(Map 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; /// Connect the generated [_$PersonToJson] function to the `toJson` method. Map toJson() => _$WalletCategoryToJson(this); @override String toString() { return name; } } Map _iconDataToJson(IconData icon) => {'codepoint': icon.codePoint, 'family': icon.fontFamily}; IconData _iconDataFromJson(Map data) => IconData(data['codepoint'] as int, fontFamily: data['family'] as String?); /// Type of entry, either expense or income enum EntryType { /// Expense expense, /// Income income }