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_design.dart';
5 : import 'package:app_finance/_classes/herald/app_locale.dart';
6 : import 'package:app_finance/_classes/structure/account_app_data.dart';
7 : import 'package:app_finance/_configs/account_type.dart';
8 : import 'package:app_finance/_ext/build_context_ext.dart';
9 : import 'package:app_finance/_configs/custom_text_theme.dart';
10 : import 'package:app_finance/design/wrapper/number_wrapper.dart';
11 : import 'package:app_finance/design/wrapper/row_widget.dart';
12 : import 'package:app_finance/_configs/theme_helper.dart';
13 : import 'package:app_finance/design/wrapper/text_wrapper.dart';
14 : import 'package:material_ui/material_ui.dart';
15 :
16 : class AccountLineWidget extends StatelessWidget {
17 : final AccountAppData item;
18 : final double width;
19 : final int count;
20 :
21 1 : const AccountLineWidget({
22 : super.key,
23 : required this.item,
24 : required this.width,
25 : required this.count,
26 : });
27 :
28 1 : @override
29 : Widget build(BuildContext context) {
30 1 : final textTheme = context.textTheme;
31 1 : final indent = ThemeHelper.getIndent();
32 5 : final txtWidth = ThemeHelper.getTextWidth(Text(item.detailsFormatted, style: textTheme.numberMedium));
33 5 : final labelWidth = ThemeHelper.getTextWidth(Text(AppLocale.labels.validTillDate, style: textTheme.bodySmall));
34 6 : final typeWidth = ThemeHelper.getTextWidth(Text(AccountType.getLabel(item.type), style: textTheme.bodySmall));
35 5 : final dateWidth = ThemeHelper.getTextWidth(Text(item.closedAtFormatted, style: textTheme.numberSmall));
36 4 : final showValidDate = !AccountType.contains(item.type, [AppAccountType.account, AppAccountType.cash]);
37 2 : if (count > 2) {
38 0 : return Padding(
39 0 : padding: EdgeInsets.symmetric(vertical: indent),
40 0 : child: RowWidget(
41 : indent: indent,
42 0 : alignment: AppDesign.getAlignment<MainAxisAlignment>(),
43 0 : maxWidth: width,
44 : chunk: const [20, null, 0.3, 0.15, 0.1],
45 0 : children: [
46 0 : [
47 0 : Icon(item.icon, color: item.color, size: 20),
48 : ],
49 0 : [
50 0 : TextWrapper(
51 0 : item.title,
52 0 : style: textTheme.headlineMedium?.copyWith(
53 0 : fontStyle: item.skip ? FontStyle.italic : FontStyle.normal,
54 : ),
55 : ),
56 : ],
57 0 : [
58 0 : NumberWidget(item.description ?? '', colorScheme: context.colorScheme, style: textTheme.headlineMedium),
59 : ],
60 0 : [
61 0 : TextWrapper(AccountType.getLabel(item.type), style: textTheme.headlineMedium),
62 : ],
63 0 : [
64 0 : Row(
65 : mainAxisAlignment: MainAxisAlignment.end,
66 0 : children: [
67 0 : Align(
68 : alignment: Alignment.centerRight,
69 0 : child: NumberWidget(
70 0 : item.detailsFormatted,
71 0 : colorScheme: context.colorScheme,
72 0 : style: textTheme.numberMedium,
73 : ),
74 : ),
75 0 : if (item.error != null) item.error!,
76 : ],
77 : ),
78 : ],
79 : ],
80 : ),
81 : );
82 : }
83 1 : return Column(
84 1 : children: [
85 1 : RowWidget(
86 : indent: indent,
87 1 : alignment: AppDesign.getAlignment<MainAxisAlignment>(),
88 1 : maxWidth: width,
89 6 : chunk: [20, null, txtWidth + 2 * indent, if (item.error != null) 22],
90 1 : children: [
91 1 : [
92 5 : Icon(item.icon, color: item.color, size: 20),
93 : ],
94 1 : [
95 1 : TextWrapper(
96 2 : item.title,
97 2 : style: textTheme.headlineMedium?.copyWith(
98 2 : fontStyle: item.skip ? FontStyle.italic : FontStyle.normal,
99 : ),
100 : ),
101 : ],
102 1 : [
103 1 : Align(
104 : alignment: Alignment.centerRight,
105 1 : child: NumberWidget(
106 2 : item.detailsFormatted,
107 1 : colorScheme: context.colorScheme,
108 1 : style: textTheme.numberMedium,
109 : ),
110 : ),
111 : ],
112 5 : if (item.error != null) [item.error!],
113 : ],
114 : ),
115 1 : RowWidget(
116 : indent: indent,
117 1 : alignment: AppDesign.getAlignment<MainAxisAlignment>(),
118 1 : maxWidth: width,
119 1 : chunk: [
120 2 : typeWidth + indent / 2,
121 : null,
122 2 : if (showValidDate) ...[labelWidth + indent, dateWidth]
123 : ],
124 1 : children: [
125 1 : [
126 1 : TextWrapper(
127 3 : AccountType.getLabel(item.type),
128 2 : style: textTheme.bodySmall?.copyWith(fontWeight: FontWeight.bold),
129 : )
130 : ],
131 1 : [
132 1 : TextWrapper(
133 2 : item.description ?? '',
134 1 : style: textTheme.numberSmall,
135 : )
136 : ],
137 1 : if (showValidDate) ...[
138 1 : [
139 1 : TextWrapper(
140 2 : AppLocale.labels.validTillDate,
141 2 : style: textTheme.bodySmall?.copyWith(fontWeight: FontWeight.bold),
142 : )
143 : ],
144 1 : [
145 1 : TextWrapper(
146 2 : item.closedAtFormatted,
147 1 : style: textTheme.numberSmall,
148 : ),
149 : ],
150 : ]
151 : ],
152 : ),
153 : ],
154 : );
155 : }
156 : }
|