Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved. 2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file. 3 : 4 : import 'package:app_finance/_classes/structure/abstract_app_data.dart'; 5 : import 'package:app_finance/_classes/structure/account_app_data.dart'; 6 : import 'package:app_finance/_classes/structure/budget_app_data.dart'; 7 : import 'package:app_finance/_classes/storage/app_data.dart'; 8 : import 'package:app_finance/_ext/date_time_ext.dart'; 9 : import 'package:app_finance/_mixins/storage_mixin.dart'; 10 : import 'package:flutter/material.dart'; 11 : import 'package:flutter_currency_picker/flutter_currency_picker.dart'; 12 : 13 : class BillAppData extends AbstractAppData with StorageMixin { 14 : String account; 15 : String category; 16 : 17 1 : BillAppData({ 18 : required this.account, 19 : required this.category, 20 : super.uuid, 21 : super.title = '', 22 : super.details, 23 : super.currency, 24 : super.updatedAt, 25 : super.createdAt, 26 : super.createdAtFormatted, 27 : super.hidden, 28 : }); 29 : 30 1 : @override 31 : String getClassName() => 'BillAppData'; 32 : 33 1 : @override 34 : AppDataType getType() => AppDataType.bills; 35 : 36 1 : @override 37 : BillAppData clone() { 38 1 : return BillAppData( 39 1 : uuid: super.uuid, 40 1 : account: account, 41 1 : category: category, 42 1 : title: super.title, 43 1 : details: super.details, 44 1 : currency: super.currency, 45 1 : createdAt: super.createdAt, 46 1 : hidden: super.hidden, 47 : ); 48 : } 49 : 50 0 : factory BillAppData.fromJson(Map<String, dynamic> json) { 51 0 : return BillAppData( 52 0 : uuid: json['uuid'], 53 0 : account: json['account'], 54 0 : category: json['category'], 55 0 : title: json['title'], 56 0 : details: 0.0 + json['details'], 57 0 : currency: CurrencyProvider.find(json['currency']), 58 0 : updatedAt: DateTime.parse(json['updatedAt']), 59 0 : createdAt: DateTime.parse(json['createdAt']), 60 0 : hidden: json['hidden'], 61 : ); 62 : } 63 : 64 1 : @override 65 1 : Map<String, dynamic> toJson() => { 66 1 : ...super.toJson(), 67 2 : 'account': account, 68 2 : 'category': category, 69 : }; 70 : 71 4 : String get detailsFormatted => (super.details as double).toCurrency(currency: currency, withPattern: false); 72 : 73 1 : @override 74 : String get description { 75 3 : AccountAppData? type = getState().getByUuid(account); 76 5 : return super.createdAt.monthDay() + (type != null ? ' (${type.title})' : ''); 77 : } 78 : 79 0 : String get accountNamed => getState().getByUuid(account)?.title ?? '?'; 80 : 81 1 : @override 82 : MaterialColor? get color { 83 3 : BudgetAppData? budget = getState().getByUuid(category); 84 1 : return budget?.color; 85 : } 86 : 87 1 : @override 88 : IconData? get icon { 89 3 : BudgetAppData? budget = getState().getByUuid(category); 90 1 : return budget?.icon; 91 : } 92 : }