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/controller/flow_state_machine.dart';
6 : import 'package:app_finance/_classes/storage/app_data.dart';
7 : import 'package:app_finance/_classes/structure/bill_app_data.dart';
8 : import 'package:app_finance/_configs/theme_helper.dart';
9 : import 'package:app_finance/_classes/structure/navigation/app_route.dart';
10 : import 'package:app_finance/design/button/full_sized_button_widget.dart';
11 : import 'package:app_finance/design/wrapper/background_wrapper.dart';
12 : import 'package:app_finance/pages/_interfaces/abstract_page_state.dart';
13 : import 'package:app_finance/pages/bill/widgets/bill_header_widget.dart';
14 : import 'package:app_finance/design/wrapper/confirmation_wrapper.dart';
15 : import 'package:app_finance/pages/bill/widgets/bill_line_widget.dart';
16 : import 'package:app_finance/pages/bill/bill_split_page.dart';
17 : import 'package:material_ui/material_ui.dart';
18 :
19 : class BillViewPage extends StatefulWidget {
20 : final String uuid;
21 :
22 0 : const BillViewPage({
23 : super.key,
24 : required this.uuid,
25 : });
26 :
27 0 : @override
28 0 : BillViewPageState createState() => BillViewPageState();
29 : }
30 :
31 : class BillViewPageState extends AbstractPageState<BillViewPage> {
32 0 : @override
33 : void initState() {
34 0 : super.initState();
35 : }
36 :
37 0 : @override
38 0 : String getTitle() => (state.getByUuid(widget.uuid) as BillAppData).title;
39 :
40 0 : @override
41 : String getButtonName() => '';
42 :
43 0 : @override
44 : Widget buildButton(BuildContext context, BoxConstraints constraints) {
45 0 : double indent = ThemeHelper.getIndent(4);
46 0 : NavigatorState nav = Navigator.of(context);
47 0 : return Container(
48 0 : margin: EdgeInsets.only(left: 2 * indent, right: 2 * indent),
49 0 : child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
50 0 : FloatingActionButton(
51 : heroTag: 'bill_view_page_edit',
52 0 : onPressed: () => nav.pushNamed(AppRoute.billEditRoute, arguments: {routeArguments.uuid: widget.uuid}),
53 0 : tooltip: AppLocale.labels.editBillTooltip,
54 : child: const Icon(Icons.edit),
55 : ),
56 0 : FloatingActionButton(
57 : heroTag: 'bill_view_page_deactivate',
58 0 : onPressed: () => ConfirmationWrapper.show(
59 : context,
60 0 : () => FlowStateMachine.deactivate(nav, store: super.state, uuid: widget.uuid),
61 : ),
62 0 : tooltip: AppLocale.labels.deleteBillTooltip,
63 : child: const Icon(Icons.delete),
64 : ),
65 : ]),
66 : );
67 : }
68 :
69 0 : @override
70 : Widget buildContent(BuildContext context, BoxConstraints constraints) {
71 0 : final indent = ThemeHelper.getIndent();
72 0 : final item = state.getByUuid(widget.uuid) as BillAppData;
73 0 : final width = ThemeHelper.getWidth(context, 2, constraints);
74 0 : final bills = state
75 0 : .getStream<BillAppData>(AppDataType.bills, filter: (e) => e.childOf != widget.uuid)
76 0 : .toList()
77 0 : .cast<BillAppData>();
78 0 : return SingleChildScrollView(
79 0 : padding: EdgeInsets.only(top: indent),
80 0 : child: Column(
81 0 : children: [
82 0 : BillHeaderWidget(
83 : item: item,
84 : width: width,
85 : ),
86 : ThemeHelper.hIndent05,
87 : const Divider(height: 2),
88 0 : Padding(
89 0 : padding: EdgeInsets.all(indent),
90 0 : child: Column(
91 0 : children: [
92 0 : ListView.builder(
93 : scrollDirection: Axis.vertical,
94 : shrinkWrap: true,
95 : physics: const NeverScrollableScrollPhysics(),
96 0 : itemCount: bills.length,
97 0 : itemBuilder: (_, int index) {
98 0 : BillAppData item = bills[index];
99 0 : final account = state.getByUuid(item.account);
100 0 : final budget = state.getByUuid(item.category);
101 0 : return BackgroundWrapper(
102 : index: index,
103 0 : child: BillLineWidget(
104 0 : width: width - 2 * indent,
105 0 : uuid: item.uuid ?? '',
106 0 : title: item.title,
107 0 : details: item.detailsFormatted,
108 0 : description: item.description,
109 0 : color: item.color ?? Colors.transparent,
110 0 : icon: item.icon ?? Icons.question_mark,
111 0 : descriptionColor: account?.color ?? Colors.transparent,
112 0 : iconTooltip: budget?.title ?? '?',
113 : ),
114 : );
115 : },
116 : ),
117 0 : FullSizedButtonWidget(
118 0 : onPressed: () => Navigator.of(context).push(
119 0 : MaterialPageRoute(
120 0 : builder: (context) => BillSplitPage(uuid: widget.uuid),
121 : ),
122 : ),
123 0 : title: AppLocale.labels.splitHeadline,
124 : icon: Icons.account_balance_wallet_outlined,
125 : ),
126 : const Divider(),
127 : // Images
128 : ThemeHelper.formEndBox,
129 : ],
130 : ),
131 : ),
132 : ],
133 : ),
134 : );
135 : }
136 : }
|