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 'dart:math';
5 :
6 : import 'package:app_finance/_classes/herald/app_design.dart';
7 : import 'package:app_finance/_classes/herald/app_locale.dart';
8 : import 'package:app_finance/_classes/storage/app_data.dart';
9 : import 'package:app_finance/_classes/structure/bill_app_data.dart';
10 : import 'package:app_finance/_classes/structure/budget_app_data.dart';
11 : import 'package:app_finance/_classes/structure/currency/exchange.dart';
12 : import 'package:app_finance/_configs/theme_helper.dart';
13 : import 'package:app_finance/_ext/build_context_ext.dart';
14 : import 'package:app_finance/charts/data/data_handler.dart';
15 : import 'package:app_finance/charts/forecast_chart.dart';
16 : import 'package:app_finance/charts/interface/chart_data.dart';
17 : import 'package:app_finance/components/widgets/account_flow_chart.dart';
18 : import 'package:app_finance/design/wrapper/row_widget.dart';
19 : import 'package:app_finance/design/wrapper/text_wrapper.dart';
20 : import 'package:material_ui/material_ui.dart';
21 : import 'package:provider/provider.dart';
22 :
23 : class BudgetForecastChart extends AccountFlowChart {
24 2 : const BudgetForecastChart({super.key});
25 :
26 0 : @override
27 : Widget build(BuildContext context) {
28 0 : double indent = ThemeHelper.getIndent();
29 0 : final TextTheme textTheme = context.textTheme;
30 0 : return Consumer<AppData>(builder: (context, appState, _) {
31 0 : final exchange = Exchange(store: appState);
32 0 : return LayoutBuilder(builder: (context, constraints) {
33 0 : final width = constraints.maxWidth - indent * 2;
34 0 : return Column(
35 0 : crossAxisAlignment: AppDesign.getAlignment(),
36 0 : children: [
37 0 : TextWrapper(
38 0 : AppLocale.labels.chartForecast,
39 0 : style: textTheme.bodyLarge,
40 : ),
41 0 : ForecastChart(
42 : width: width,
43 0 : height: [constraints.maxHeight - 6 * indent, 200].reduce(min).toDouble(),
44 : indent: indent,
45 0 : data: [
46 0 : ChartData(DataHandler.getAmountGroupedByDate(
47 0 : appState.getActualList(AppDataType.bills).cast<BillAppData>(),
48 : exchange: exchange,
49 : )),
50 : ],
51 0 : yMax: DataHandler.countBudgetTotal(
52 0 : appState.getList(AppDataType.budgets).cast<BudgetAppData>().where((v) => !v.skip).toList(),
53 : exchange: exchange,
54 : ),
55 : ),
56 0 : RowWidget(
57 : maxWidth: width,
58 : indent: indent,
59 : chunk: const [null, null],
60 0 : children: [
61 0 : [
62 0 : Padding(
63 0 : padding: EdgeInsets.only(left: indent * 2),
64 0 : child: TextWrapper(
65 0 : AppLocale.labels.actualData,
66 0 : style: textTheme.bodySmall!.copyWith(color: Colors.red),
67 : ),
68 : ),
69 : ],
70 0 : [
71 0 : Align(
72 : alignment: Alignment.centerRight,
73 0 : child: TextWrapper(
74 0 : AppLocale.labels.forecastData,
75 0 : style: textTheme.bodySmall!.copyWith(color: Colors.red.withBlue(200)),
76 : ),
77 : ),
78 : ],
79 : ],
80 : ),
81 : ],
82 : );
83 : });
84 : });
85 : }
86 : }
|