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 1 : 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 1 : @override
31 : Widget buildGroupedListWidget(List<dynamic> items, BuildContext context) {
32 1 : final item = wrapBySingleEntity(items);
33 4 : double total = items.fold(0.0, (value, e) => value + e.progressLeft);
34 1 : if (total == 0) {
35 : total = 1;
36 : }
37 1 : return BaseGroupWidget(
38 1 : title: item.title,
39 1 : total: item.details,
40 1 : description: item.description,
41 8 : progress: items.map((e) => item.progressLeft * e.progressLeft / total).cast<double>().toList(),
42 5 : color: items.map((e) => e.color ?? Colors.transparent).cast<Color>().toList(),
43 4 : width: width - ThemeHelper.getIndent() / 2,
44 : items: items,
45 : route: AppRoute.budgetRoute,
46 : );
47 : }
48 :
49 1 : @override
50 : dynamic wrapBySingleEntity(List<dynamic> items) {
51 2 : Currency? def = exchange.getDefaultCurrency();
52 7 : double amountLimit = items.fold(0.0, (value, e) => value + exchange.reform(e.amountLimit, e.currency, def));
53 7 : double amountSpent = items.fold(0.0, (value, e) => value + exchange.reform(e.amount, e.currency, def));
54 4 : double progress = amountLimit > 0 ? 1 - (amountLimit - amountSpent) / amountLimit : 0.0;
55 1 : return BudgetAppData(
56 2 : title: getName(items.first),
57 : currency: def,
58 : amountLimit: amountLimit,
59 : progress: progress,
60 : );
61 : }
62 :
63 1 : @override
64 : Widget buildSingleListWidget(item, BuildContext context) {
65 2 : item = item is List ? item.first : item;
66 1 : return BaseSwipeWidget(
67 : routePath: AppRoute.budgetEditRoute,
68 1 : uuid: item.uuid,
69 1 : child: BaseLineWidget(
70 1 : uuid: item.uuid,
71 1 : title: item.title,
72 1 : description: item.description ?? '',
73 1 : details: item.detailsFormatted,
74 1 : progress: item.progressLeft,
75 1 : color: item.color ?? Colors.transparent,
76 1 : icon: item.icon ?? Icons.radio_button_unchecked_sharp,
77 1 : hidden: item.hidden,
78 1 : skip: item.skip,
79 1 : width: width,
80 1 : route: routeList,
81 : ),
82 : );
83 : }
84 : }
|