import 'package:currency_picker/currency_picker.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:prasule/api/category.dart'; import 'package:prasule/api/walletentry.dart'; part 'wallet.g.dart'; Currency _currencyFromJson(Map data) => Currency.from(json: data); @JsonSerializable() class Wallet { final String name; final List categories; final List entries; double starterBalance; @JsonKey(fromJson: _currencyFromJson) final Currency currency; Wallet( {required this.name, required this.currency, this.categories = const [], this.entries = const [], this.starterBalance = 0}); /// Connect the generated [_$WalletEntry] function to the `fromJson` /// factory. factory Wallet.fromJson(Map json) => _$WalletFromJson(json); /// Connect the generated [_$PersonToJson] function to the `toJson` method. Map toJson() => _$WalletToJson(this); /// Getter for the next unused unique number ID in the wallet's entry list int get nextId { var id = 1; while (entries.where((element) => element.id == id).isNotEmpty) { id++; // create unique ID } return id; } static final Wallet empty = Wallet( name: "Empty", currency: Currency.from( json: { "code": "USD", "name": "United States Dollar", "symbol": "\$", "flag": "USD", "decimal_digits": 2, "number": 840, "name_plural": "US dollars", "thousands_separator": ",", "decimal_separator": ".", "space_between_amount_and_symbol": false, "symbol_on_left": true, }, ), ); }