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/navigation/app_route.dart';
5 : import 'package:app_finance/_classes/structure/budget_app_data.dart';
6 : import 'package:app_finance/_configs/theme_helper.dart';
7 : import 'package:app_finance/design/generic/base_swipe_widget.dart';
8 : import 'package:app_finance/components/widgets/account_widget.dart';
9 : import 'package:app_finance/design/generic/base_group_widget.dart';
10 : import 'package:app_finance/design/generic/base_line_widget.dart';
11 : import 'package:material_ui/material_ui.dart';
12 : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
13 :
14 : class BudgetWidget extends AccountWidget {
15 6 : BudgetWidget({
16 : super.key,
17 : required super.title,
18 : required super.width,
19 : required super.margin,
20 : required super.state,
21 : super.tooltip,
22 : super.limit,
23 : super.route,
24 : super.routeList = AppRoute.budgetViewRoute,
25 : super.hasExpand,
26 : super.toExpand,
27 : super.callback,
28 : });
29 :
30 0 : @override
31 : Widget buildGroupedListWidget(List<dynamic> items, BuildContext context) {
32 0 : final item = wrapBySingleEntity(items);
33 0 : double total = items.fold(0.0, (value, e) => value + e.progressLeft);
34 0 : if (total == 0) {
35 : total = 1;
36 : }
37 0 : return BaseGroupWidget(
38 0 : title: item.title,
39 0 : total: item.details,
40 0 : description: item.description,
41 0 : progress: items.map((e) => item.progressLeft * e.progressLeft / total).cast<double>().toList(),
42 0 : color: items.map((e) => e.color ?? Colors.transparent).cast<Color>().toList(),
43 0 : width: width - ThemeHelper.getIndent() / 2,
44 : items: items,
45 : route: AppRoute.budgetRoute,
46 : );
47 : }
48 :
49 0 : @override
50 : dynamic wrapBySingleEntity(List<dynamic> items) {
51 0 : Currency? def = exchange.getDefaultCurrency();
52 0 : double amountLimit = items.fold(0.0, (value, e) => value + exchange.reform(e.amountLimit, e.currency, def));
53 0 : double amountSpent = items.fold(0.0, (value, e) => value + exchange.reform(e.amount, e.currency, def));
54 0 : double progress = amountLimit > 0 ? 1 - (amountLimit - amountSpent) / amountLimit : 0.0;
55 0 : return BudgetAppData(
56 0 : title: getName(items.first),
57 : currency: def,
58 : amountLimit: amountLimit,
59 : progress: progress,
60 : );
61 : }
62 :
63 2 : @override
64 : Widget buildSingleListWidget(item, BuildContext context) {
65 4 : item = item is List ? item.first : item;
66 2 : return BaseSwipeWidget(
67 : routePath: AppRoute.budgetEditRoute,
68 2 : uuid: item.uuid,
69 2 : child: BaseLineWidget(
70 2 : uuid: item.uuid,
71 2 : title: item.title,
72 2 : description: item.description ?? '',
73 2 : details: item.detailsFormatted,
74 2 : progress: item.progressLeft,
75 2 : color: item.color ?? Colors.transparent,
76 2 : icon: item.icon ?? Icons.radio_button_unchecked_sharp,
77 2 : hidden: item.hidden,
78 2 : skip: item.skip,
79 2 : width: width,
80 2 : route: routeList,
81 : ),
82 : );
83 : }
84 : }
|