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/herald/app_locale.dart';
5 : import 'package:app_finance/_classes/storage/app_preferences.dart';
6 : import 'package:app_finance/_classes/structure/navigation/app_route.dart';
7 : import 'package:app_finance/_configs/theme_helper.dart';
8 : import 'package:app_finance/pages/_interfaces/abstract_page_state.dart';
9 : import 'package:app_finance/pages/start/widgets/about_tab.dart';
10 : import 'package:app_finance/pages/start/widgets/account_about_tab.dart';
11 : import 'package:app_finance/pages/start/widgets/budget_about_tab.dart';
12 : import 'package:app_finance/pages/start/widgets/usage_tab.dart';
13 : import 'package:app_finance/design/button/full_sized_button_widget.dart';
14 : import 'package:app_finance/design/wrapper/tab_widget.dart';
15 : import 'package:app_finance/pages/start/widgets/account_tab.dart';
16 : import 'package:app_finance/pages/start/widgets/budget_tab.dart';
17 : import 'package:app_finance/pages/start/widgets/privacy_tab.dart';
18 : import 'package:app_finance/pages/start/widgets/setting_tab.dart';
19 : import 'package:app_finance/design/button/toolbar_button_widget.dart';
20 : import 'package:material_ui/material_ui.dart';
21 :
22 : class StartPage extends StatefulWidget {
23 2 : const StartPage({super.key});
24 :
25 0 : @override
26 0 : StartPageState createState() => StartPageState();
27 : }
28 :
29 : class StartPageState extends AbstractPageState<StartPage> {
30 : int currentStep = 0;
31 : static const acknowledgeTaken = 3;
32 : static const finalStep = 4;
33 : Widget button = ThemeHelper.emptyBox;
34 : List<Widget> barActions = [];
35 : String buttonName = AppLocale.labels.goNextTooltip;
36 :
37 0 : @override
38 : void initState() {
39 0 : AppPreferences.set(AppPreferences.prefPrivacyPolicy, 'true');
40 0 : super.initState();
41 : }
42 :
43 0 : @override
44 0 : String getTitle() => AppLocale.labels.appStartHeadline;
45 :
46 0 : @override
47 0 : String getButtonName() => buttonName;
48 :
49 0 : @override
50 0 : Widget buildButton(BuildContext context, BoxConstraints constraints) => button;
51 :
52 0 : @override
53 0 : List<Widget> getBarActions(NavigatorState nav) => barActions;
54 :
55 0 : @override
56 : Widget? buildNavigation() => null;
57 :
58 0 : @override
59 : Widget? getBarLeading(NavigatorState nav) => ThemeHelper.emptyBox;
60 :
61 0 : void _setButton(Widget btn, NavigatorState nav) => setState(() {
62 0 : button = btn;
63 0 : buttonName = (btn as FullSizedButtonWidget).title;
64 0 : if (barActions.isEmpty && currentStep > acknowledgeTaken) {
65 0 : barActions = [
66 0 : ToolbarButtonWidget(
67 : icon: Icons.skip_next,
68 : color: Colors.white70,
69 0 : tooltip: AppLocale.labels.skipTooltip,
70 0 : onPressed: () => nav.pushNamed(AppRoute.homeRoute),
71 : ),
72 : ];
73 : }
74 : });
75 :
76 0 : void _goNext(int step) => setState(() {
77 0 : button = ThemeHelper.emptyBox;
78 0 : currentStep = step + 1;
79 : });
80 :
81 0 : void _finalize(NavigatorState nav) => nav.popAndPushNamed(AppRoute.homeRoute);
82 :
83 0 : @override
84 : Widget buildContent(BuildContext context, BoxConstraints constraints) {
85 0 : NavigatorState nav = Navigator.of(context);
86 0 : fn(Widget btn) => _setButton(btn, nav);
87 0 : final isEmpty = button == ThemeHelper.emptyBox;
88 : int i = 0;
89 0 : return Padding(
90 0 : padding: EdgeInsets.only(top: ThemeHelper.getIndent(0.5)),
91 0 : child: TabWidget(
92 : type: TabType.dots,
93 0 : callback: (i) => _goNext(--i),
94 0 : focus: currentStep,
95 0 : children: [
96 0 : AboutTab(
97 : setButton: fn,
98 0 : setState: () => _goNext(0),
99 0 : isFirstBoot: currentStep == i++ && isEmpty,
100 : ),
101 0 : PrivacyTab(
102 : setButton: fn,
103 0 : setState: () => _goNext(1),
104 0 : isFirstBoot: currentStep == i++ && isEmpty,
105 : ),
106 0 : UsageTab(
107 : setButton: fn,
108 0 : setState: () => _goNext(2),
109 0 : isFirstBoot: currentStep == i++ && isEmpty,
110 : ),
111 0 : SettingTab(
112 : setButton: fn,
113 0 : setState: () => _goNext(3),
114 0 : isFirstBoot: currentStep == i++ && isEmpty,
115 : ),
116 0 : AccountAboutTab(
117 : setButton: fn,
118 0 : setState: () => _goNext(4),
119 0 : isFirstBoot: currentStep == i++ && isEmpty,
120 : ),
121 0 : AccountTab(
122 : setButton: fn,
123 0 : setState: () => _goNext(5),
124 0 : isFirstBoot: currentStep == i++ && isEmpty,
125 : ),
126 0 : BudgetAboutTab(
127 : setButton: fn,
128 0 : setState: () => _goNext(6),
129 0 : isFirstBoot: currentStep == i++ && isEmpty,
130 : ),
131 0 : BudgetTab(
132 : setButton: fn,
133 0 : setState: () => _finalize(nav),
134 0 : isFirstBoot: currentStep == i++ && isEmpty,
135 : ),
136 : ],
137 : ),
138 : );
139 : }
140 : }
|