Line data Source code
1 : // Copyright 2024 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/herald/app_locale.dart';
5 : import 'package:app_finance/components/widgets/account_flow_chart.dart';
6 : import 'package:app_finance/components/widgets/account_health_chart.dart';
7 : import 'package:app_finance/components/widgets/bill_ytd_chart.dart';
8 : import 'package:app_finance/components/widgets/budget_forecast_chart.dart';
9 : import 'package:app_finance/components/widgets/budget_ytd_chart.dart';
10 : import 'package:app_finance/design/form/list_selector_item.dart';
11 : import 'package:app_finance/_configs/theme_helper.dart';
12 : import 'package:app_finance/_ext/build_context_ext.dart';
13 : import 'package:app_finance/_ext/string_ext.dart';
14 : import 'package:app_finance/components/_core/component_data.dart';
15 : import 'package:app_finance/design/form/list_selector.dart';
16 : import 'package:material_ui/material_ui.dart';
17 :
18 : enum ComponentChartType {
19 : accountFlow,
20 : accountHealth,
21 : billYtd,
22 : budgetForecast,
23 : budgetYtd,
24 : }
25 :
26 : class ComponentChart extends StatelessWidget {
27 : final ComponentData data;
28 :
29 0 : const ComponentChart(this.data, {super.key});
30 :
31 0 : @override
32 : Widget build(BuildContext context) {
33 0 : ComponentChartType? widgetType = data[componentData.type]?.toString().toEnum(ComponentChartType.values);
34 0 : return Container(
35 0 : padding: EdgeInsets.all(ThemeHelper.getIndent()),
36 : child: switch (widgetType) {
37 0 : ComponentChartType.accountFlow => const AccountFlowChart(),
38 0 : ComponentChartType.accountHealth => const AccountHealthChart(),
39 0 : ComponentChartType.billYtd => const BillYtdChart(),
40 0 : ComponentChartType.budgetForecast => const BudgetForecastChart(),
41 0 : ComponentChartType.budgetYtd => const BudgetYtdChart(),
42 : _ => ThemeHelper.emptyBox,
43 : },
44 : );
45 : }
46 : }
47 :
48 : class ComponentChartForm extends StatefulWidget {
49 : final ComponentData data;
50 : final Function adjust;
51 :
52 0 : const ComponentChartForm(this.data, {super.key, required this.adjust});
53 :
54 0 : @override
55 0 : ComponentChartFormState createState() => ComponentChartFormState();
56 : }
57 :
58 : class ComponentChartFormState extends State<ComponentChartForm> {
59 : late String? _option;
60 :
61 0 : @override
62 : initState() {
63 0 : super.initState();
64 0 : _option = widget.data[componentData.type];
65 : }
66 :
67 0 : @override
68 : dispose() {
69 0 : super.dispose();
70 : }
71 :
72 0 : @override
73 : Widget build(BuildContext context) {
74 0 : return Container(
75 0 : color: context.colorScheme.surface,
76 0 : padding: EdgeInsets.only(left: ThemeHelper.getIndent(2), right: ThemeHelper.getIndent()),
77 : height: double.infinity,
78 0 : child: SingleChildScrollView(
79 0 : child: Column(
80 0 : children: [
81 : ThemeHelper.hIndent3x,
82 0 : ListSelector<ListSelectorItem>(
83 0 : setState: (value) {
84 0 : setState(() => _option = value?.id);
85 0 : widget.adjust(widget.data[componentData.order], {...widget.data, componentData.type: value?.id});
86 : },
87 0 : hintText: AppLocale.labels.cmpChart,
88 0 : value: _option != null ? ListSelectorItem(id: _option!, name: '') : null,
89 0 : options: [
90 0 : ListSelectorItem(id: ComponentChartType.accountFlow.toString(), name: AppLocale.labels.chartOHLC),
91 0 : ListSelectorItem(id: ComponentChartType.accountHealth.toString(), name: AppLocale.labels.incomeHealth),
92 0 : ListSelectorItem(id: ComponentChartType.billYtd.toString(), name: AppLocale.labels.chartYtdExpense),
93 0 : ListSelectorItem(
94 0 : id: ComponentChartType.budgetForecast.toString(), name: AppLocale.labels.chartForecast),
95 0 : ListSelectorItem(id: ComponentChartType.budgetYtd.toString(), name: AppLocale.labels.budgetHeadline),
96 : ],
97 : ),
98 : ThemeHelper.hIndent,
99 : ],
100 : ),
101 : ),
102 : );
103 : }
104 : }
|