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 1 : 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 1 : }) : super(key: key);
46 :
47 1 : Widget buildListWidget(item, BuildContext context) {
48 1 : return BaseSwipeWidget(
49 2 : routePath: routeList.replaceAll('/view', '/edit'),
50 1 : uuid: item.uuid,
51 1 : child: BaseLineWidget(
52 1 : uuid: item.uuid ?? '',
53 1 : title: item.title,
54 1 : description: item.description ?? '',
55 1 : details: item.detailsFormatted,
56 1 : progress: item.progress,
57 1 : color: item.color ?? Colors.transparent,
58 1 : icon: item.icon ?? Icons.radio_button_unchecked_sharp,
59 1 : hidden: item.hidden,
60 1 : width: width,
61 1 : 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 1 : @override
75 : Widget build(BuildContext context) {
76 1 : if (!hasExpand || (toExpand ?? '') == '' || toExpand == title) {
77 1 : 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 1 : Widget buildFull(BuildContext context) {
122 1 : return Expanded(
123 1 : child: Container(
124 1 : margin: margin,
125 1 : child: Column(
126 1 : crossAxisAlignment: AppDesign.getAlignment(),
127 1 : children: [
128 1 : BaseHeaderWidget(
129 1 : route: route,
130 1 : width: width,
131 1 : total: state.total,
132 1 : title: title,
133 1 : tooltip: tooltip,
134 1 : hasExpand: hasExpand,
135 2 : toExpand: (toExpand ?? '') == '' || toExpand != title,
136 1 : expand: _expand,
137 : ),
138 1 : Expanded(
139 1 : child: limit != null
140 1 : ? BaseListLimitedWidget(
141 1 : route: route,
142 1 : state: state.list,
143 1 : limit: limit,
144 1 : routeList: routeList,
145 1 : width: width,
146 1 : 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 : }
|