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/storage/app_data.dart';
5 : import 'package:app_finance/_classes/herald/app_locale.dart';
6 : import 'package:app_finance/_classes/structure/goal_app_data.dart';
7 : import 'package:app_finance/_configs/theme_helper.dart';
8 : import 'package:app_finance/_classes/structure/navigation/app_route.dart';
9 : import 'package:app_finance/design/wrapper/background_wrapper.dart';
10 : import 'package:app_finance/pages/_interfaces/abstract_page_state.dart';
11 : import 'package:app_finance/pages/goal/widgets/goal_line_widget.dart';
12 : import 'package:app_finance/pages/goal/widgets/header_widget.dart';
13 : import 'package:app_finance/pages/goal/widgets/profit_widget.dart';
14 : import 'package:flutter/material.dart';
15 :
16 : class GoalPage extends StatefulWidget {
17 5 : const GoalPage({super.key});
18 :
19 1 : @override
20 1 : GoalPageState createState() => GoalPageState();
21 : }
22 :
23 : class GoalPageState extends AbstractPageState<GoalPage> {
24 1 : @override
25 : String getTitle() {
26 2 : return AppLocale.labels.goalHeadline;
27 : }
28 :
29 1 : @override
30 2 : String getButtonName() => AppLocale.labels.addGoalTooltip;
31 :
32 1 : @override
33 : Widget buildButton(BuildContext context, BoxConstraints constraints) {
34 1 : NavigatorState nav = Navigator.of(context);
35 1 : return FloatingActionButton(
36 : heroTag: 'goal_view_page',
37 0 : onPressed: () => nav.pushNamed(AppRoute.goalAddRoute),
38 1 : tooltip: getButtonName(),
39 : child: const Icon(Icons.add),
40 : );
41 : }
42 :
43 1 : @override
44 : Widget buildContent(BuildContext context, BoxConstraints constraints) {
45 1 : final width = ThemeHelper.getWidth(context, 4, constraints);
46 2 : final goals = state.getStream(AppDataType.goals);
47 1 : final widthCount = ThemeHelper.getWidthCount(constraints, context);
48 :
49 1 : return Padding(
50 2 : padding: EdgeInsets.all(ThemeHelper.getIndent()),
51 1 : child: Column(
52 1 : children: [
53 : ThemeHelper.hIndent,
54 1 : Align(
55 : alignment: Alignment.centerRight,
56 3 : child: ProfitWidget(store: state, width: width / widthCount),
57 : ),
58 : ThemeHelper.hIndent,
59 1 : if (widthCount > 1)
60 1 : HeaderWidget(
61 : count: widthCount,
62 : width: width,
63 : ),
64 1 : Expanded(
65 1 : child: ListView.builder(
66 : scrollDirection: Axis.vertical,
67 : shrinkWrap: true,
68 1 : itemCount: goals.length,
69 0 : itemBuilder: (_, int index) {
70 0 : final goal = goals.next as GoalAppData;
71 0 : return BackgroundWrapper(
72 : index: index,
73 0 : child: GoalLineWidget(
74 0 : title: goal.title,
75 : width: width,
76 : count: widthCount,
77 0 : uuid: goal.uuid ?? '',
78 0 : details: goal.details,
79 0 : currency: goal.currency,
80 0 : description: goal.closedAtFormatted,
81 0 : color: goal.color ?? Colors.green.shade700,
82 0 : icon: goal.icon ?? Icons.star,
83 0 : hidden: goal.hidden,
84 0 : progress: goal.progress,
85 : route: AppRoute.goalViewRoute,
86 : ),
87 : );
88 : },
89 : ),
90 : ),
91 : ],
92 : ),
93 : );
94 : }
95 : }
|