import 'dart:convert'; import 'package:tunas/repositories/account/models/budget.dart'; import 'package:tunas/repositories/account/models/category.dart'; import 'transaction.dart'; class Account { List transactions; List budgets; List categories; Set subAccounts; Account({ this.transactions = const [], this.budgets = const [], this.categories = const [], this.subAccounts = const {}, }); factory Account.fromJson(Map json) { return Account( transactions: (jsonDecode(json['transactions']) as List).map((transaction) => Transaction.fromJson(transaction)).toList(), budgets: (jsonDecode(json['budgets']) as List).map((budget) => Budget.fromJson(budget)).toList(), categories: (jsonDecode(json['categories']) as List).map((category) => Category.fromJson(category)).toList(), subAccounts: Set.from(jsonDecode(json['subAccounts'])), ); } Map toJson() => { 'transactions': jsonEncode(transactions.map((transaction) => transaction.toJson()).toList()), 'budgets': jsonEncode(budgets.map((budget) => budget.toJson()).toList()), 'categories': jsonEncode(categories.map((category) => category.toJson()).toList()), 'subAccounts': jsonEncode(subAccounts.toList()), }; }