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 { final EntryType type; String name; final int id; @JsonKey(fromJson: _iconDataFromJson, toJson: _iconDataToJson) IconData icon; 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); /// Connect the generated [_$PersonToJson] function to the `toJson` method. Map toJson() => _$WalletCategoryToJson(this); } Map _iconDataToJson(IconData icon) => {'codepoint': icon.codePoint, 'family': icon.fontFamily}; IconData _iconDataFromJson(Map data) => IconData(data['codepoint'], fontFamily: data['family']); enum EntryType { expense, income }