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/controller/iterator_controller.dart';
5 : import 'package:app_finance/_classes/herald/app_design.dart';
6 : import 'package:app_finance/_classes/storage/app_data.dart';
7 : import 'package:app_finance/_classes/storage/app_preferences.dart';
8 : import 'package:app_finance/_configs/custom_text_theme.dart';
9 : import 'package:app_finance/_configs/theme_helper.dart';
10 : import 'package:app_finance/_ext/build_context_ext.dart';
11 : import 'package:app_finance/design/generic/base_header_widget.dart';
12 : import 'package:app_finance/design/generic/base_line_widget.dart';
13 : import 'package:app_finance/design/generic/base_list_infinite_widget.dart';
14 : import 'package:app_finance/design/generic/base_list_limited_widget.dart';
15 : import 'package:app_finance/design/generic/base_swipe_widget.dart';
16 : import 'package:flutter/material.dart';
17 : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
18 :
19 : class BaseWidget extends StatelessWidget {
20 : final EdgeInsetsGeometry margin;
21 : final String title;
22 : final double width;
23 : final int? limit;
24 : final AppDataGetter state;
25 : final String? tooltip;
26 : final String? route;
27 : final String routeList;
28 : final bool hasExpand;
29 : final String? toExpand;
30 : final Function? callback;
31 :
32 3 : const BaseWidget({
33 : Key? key,
34 : required this.margin,
35 : required this.title,
36 : required this.state,
37 : required this.width,
38 : this.tooltip,
39 : this.limit,
40 : this.route,
41 : this.routeList = '',
42 : this.hasExpand = false,
43 : this.toExpand = '',
44 : this.callback,
45 3 : }) : super(key: key);
46 :
47 0 : Widget buildListWidget(item, BuildContext context) {
48 0 : return BaseSwipeWidget(
49 0 : routePath: routeList.replaceAll('/view', '/edit'),
50 0 : uuid: item.uuid,
51 0 : child: BaseLineWidget(
52 0 : uuid: item.uuid ?? '',
53 0 : title: item.title,
54 0 : description: item.description ?? '',
55 0 : details: item.detailsFormatted,
56 0 : progress: item.progress,
57 0 : color: item.color ?? Colors.transparent,
58 0 : icon: item.icon ?? Icons.radio_button_unchecked_sharp,
59 0 : hidden: item.hidden,
60 0 : width: width,
61 0 : route: routeList,
62 : ),
63 : );
64 : }
65 :
66 0 : void _expand() {
67 0 : String outcome = toExpand == title ? '' : title;
68 0 : AppPreferences.set(AppPreferences.prefExpand, outcome);
69 0 : if (callback != null) {
70 0 : callback!(outcome);
71 : }
72 : }
73 :
74 3 : @override
75 : Widget build(BuildContext context) {
76 3 : if (!hasExpand || (toExpand ?? '') == '' || toExpand == title) {
77 3 : return buildFull(context);
78 : }
79 0 : return buildCollapsed(context);
80 : }
81 :
82 0 : Widget buildMinimized(BuildContext context) {
83 0 : return Container(
84 0 : margin: EdgeInsets.only(top: ThemeHelper.getIndent(3)),
85 : alignment: Alignment.center,
86 0 : decoration: BoxDecoration(
87 : shape: BoxShape.circle,
88 0 : color: context.colorScheme.inverseSurface.withOpacity(0.1),
89 : ),
90 0 : height: ThemeHelper.getHeight(context),
91 0 : child: Column(
92 0 : children: [
93 0 : SizedBox(height: ThemeHelper.getHeight(context) / 2 - 2 * ThemeHelper.getTextHeight(Text(title))),
94 0 : Text(title),
95 : ThemeHelper.hIndent,
96 0 : Text(
97 0 : state.total.toCurrency(withPattern: false),
98 0 : style: context.textTheme.numberMedium,
99 : ),
100 : ],
101 : ),
102 : );
103 : }
104 :
105 0 : Widget buildCollapsed(BuildContext context) {
106 0 : return Container(
107 0 : margin: margin,
108 0 : child: BaseHeaderWidget(
109 0 : route: route,
110 0 : width: width,
111 0 : total: state.total,
112 0 : title: title,
113 0 : tooltip: tooltip,
114 0 : hasExpand: hasExpand,
115 : toExpand: true,
116 0 : expand: _expand,
117 : ),
118 : );
119 : }
120 :
121 3 : Widget buildFull(BuildContext context) {
122 3 : return Expanded(
123 3 : child: Container(
124 3 : margin: margin,
125 3 : child: Column(
126 3 : crossAxisAlignment: AppDesign.getAlignment(),
127 3 : children: [
128 3 : BaseHeaderWidget(
129 3 : route: route,
130 3 : width: width,
131 3 : total: state.total,
132 3 : title: title,
133 3 : tooltip: tooltip,
134 3 : hasExpand: hasExpand,
135 6 : toExpand: (toExpand ?? '') == '' || toExpand != title,
136 3 : expand: _expand,
137 : ),
138 3 : Expanded(
139 3 : child: limit != null
140 3 : ? BaseListLimitedWidget(
141 3 : route: route,
142 3 : state: state.list,
143 3 : limit: limit,
144 3 : routeList: routeList,
145 3 : width: width,
146 3 : buildListWidget: buildListWidget,
147 : )
148 0 : : BaseListInfiniteWidget(
149 0 : stream: state.stream as IteratorReverseController,
150 0 : width: width,
151 0 : buildListWidget: buildListWidget,
152 : ),
153 : ),
154 : ],
155 : ),
156 : ),
157 : );
158 : }
159 : }
|