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/storage/app_data.dart';
7 : import 'package:app_finance/_configs/theme_helper.dart';
8 : import 'package:app_finance/design/button/full_sized_button_widget.dart';
9 : import 'package:app_finance/pages/account/account_add_page.dart';
10 : import 'package:material_ui/material_ui.dart';
11 : import 'package:provider/provider.dart';
12 :
13 : class AccountTab extends AccountAddPage {
14 : final bool isFirstBoot;
15 : final Function() setState;
16 : final Function(Widget btn) setButton;
17 :
18 0 : const AccountTab({
19 : super.key,
20 : required this.isFirstBoot,
21 : required this.setState,
22 : required this.setButton,
23 : });
24 :
25 0 : @override
26 0 : AccountTabState createState() => AccountTabState();
27 : }
28 :
29 : class AccountTabState extends AccountAddPageState<AccountTab> {
30 0 : @override
31 : void triggerActionButton(NavigatorState nav) {
32 0 : setState(() {
33 0 : if (hasFormErrors()) {
34 : return;
35 : }
36 0 : updateStorage();
37 0 : AppPreferences.set(AppPreferences.prefAccount, super.state.getList(AppDataType.accounts).first?.uuid);
38 0 : widget.setState();
39 : });
40 : }
41 :
42 0 : Widget _nextButton(BuildContext context, BoxConstraints constraints) => FullSizedButtonWidget(
43 : constraints: constraints,
44 0 : controller: focus,
45 0 : onPressed: () => widget.setState(),
46 0 : title: AppLocale.labels.goNextTooltip,
47 : icon: Icons.exit_to_app_rounded,
48 : );
49 :
50 0 : @override
51 : Widget build(BuildContext context) {
52 0 : return Consumer<AppData>(builder: (context, appState, _) {
53 0 : state = appState;
54 0 : final isCreated = state.getList(AppDataType.accounts).isNotEmpty;
55 0 : return Padding(
56 0 : padding: EdgeInsets.only(top: ThemeHelper.getIndent(2)),
57 0 : child: LayoutBuilder(builder: (context, constraints) {
58 0 : if (widget.isFirstBoot) {
59 0 : WidgetsBinding.instance.addPostFrameCallback((_) {
60 0 : widget.setButton(
61 0 : isCreated ? _nextButton(context, constraints) : buildButton(context, constraints),
62 : );
63 : });
64 : return ThemeHelper.emptyBox;
65 : }
66 : if (isCreated) {
67 0 : return Center(child: Text(AppLocale.labels.isCreated));
68 : }
69 0 : return buildContent(context, constraints);
70 : }),
71 : );
72 : });
73 : }
74 : }
|