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