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:flutter/material.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(item.title, style: textTheme.headlineMedium),
51 : ],
52 0 : [
53 0 : NumberWidget(item.description ?? '', colorScheme: context.colorScheme, style: textTheme.headlineMedium),
54 : ],
55 0 : [
56 0 : TextWrapper(AccountType.getLabel(item.type), style: textTheme.headlineMedium),
57 : ],
58 0 : [
59 0 : Row(
60 : mainAxisAlignment: MainAxisAlignment.end,
61 0 : children: [
62 0 : Align(
63 : alignment: Alignment.centerRight,
64 0 : child: NumberWidget(
65 0 : item.detailsFormatted,
66 0 : colorScheme: context.colorScheme,
67 0 : style: textTheme.numberMedium,
68 : ),
69 : ),
70 0 : if (item.error != null) item.error!,
71 : ],
72 : ),
73 : ],
74 : ],
75 : ),
76 : );
77 : }
78 1 : return Column(
79 1 : children: [
80 1 : RowWidget(
81 : indent: indent,
82 1 : alignment: AppDesign.getAlignment<MainAxisAlignment>(),
83 1 : maxWidth: width,
84 6 : chunk: [20, null, txtWidth + 2 * indent, if (item.error != null) 22],
85 1 : children: [
86 1 : [
87 5 : Icon(item.icon, color: item.color, size: 20),
88 : ],
89 1 : [
90 4 : TextWrapper(item.title, style: textTheme.headlineMedium),
91 : ],
92 1 : [
93 1 : Align(
94 : alignment: Alignment.centerRight,
95 1 : child: NumberWidget(
96 2 : item.detailsFormatted,
97 1 : colorScheme: context.colorScheme,
98 1 : style: textTheme.numberMedium,
99 : ),
100 : ),
101 : ],
102 5 : if (item.error != null) [item.error!],
103 : ],
104 : ),
105 1 : RowWidget(
106 : indent: indent,
107 1 : alignment: AppDesign.getAlignment<MainAxisAlignment>(),
108 1 : maxWidth: width,
109 1 : chunk: [
110 2 : typeWidth + indent / 2,
111 : null,
112 2 : if (showValidDate) ...[labelWidth + indent, dateWidth]
113 : ],
114 1 : children: [
115 1 : [
116 1 : TextWrapper(
117 3 : AccountType.getLabel(item.type),
118 2 : style: textTheme.bodySmall?.copyWith(fontWeight: FontWeight.bold),
119 : )
120 : ],
121 1 : [
122 1 : TextWrapper(
123 2 : item.description ?? '',
124 1 : style: textTheme.numberSmall,
125 : )
126 : ],
127 1 : if (showValidDate) ...[
128 1 : [
129 1 : TextWrapper(
130 2 : AppLocale.labels.validTillDate,
131 2 : style: textTheme.bodySmall?.copyWith(fontWeight: FontWeight.bold),
132 : )
133 : ],
134 1 : [
135 1 : TextWrapper(
136 2 : item.closedAtFormatted,
137 1 : style: textTheme.numberSmall,
138 : ),
139 : ],
140 : ]
141 : ],
142 : ),
143 : ],
144 : );
145 : }
146 : }
|