Line data Source code
1 : // Copyright 2026 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/storage/app_data.dart';
7 : import 'package:app_finance/_configs/theme_helper.dart';
8 : import 'package:app_finance/_ext/build_context_ext.dart';
9 : import 'package:app_finance/design/button/full_sized_button_widget.dart';
10 : import 'package:app_finance/design/wrapper/input_wrapper.dart';
11 : import 'package:material_ui/material_ui.dart';
12 :
13 : class IntegrationTarget {
14 : String? appAccount;
15 : String? category;
16 : DateTime from;
17 :
18 2 : IntegrationTarget({this.appAccount, this.category, required this.from});
19 : }
20 :
21 : class IntegrationAccountCard extends StatelessWidget {
22 : final String title;
23 : final String? subtitle;
24 : final IntegrationTarget target;
25 : final AppData state;
26 : final bool isDisabled;
27 : final VoidCallback onChanged;
28 : // Without it transactions are imported automatically: the period and the button are hidden
29 : final VoidCallback? onImport;
30 : final List<Widget> children;
31 : final String? accountTitle;
32 :
33 2 : const IntegrationAccountCard({
34 : super.key,
35 : required this.title,
36 : required this.target,
37 : required this.state,
38 : required this.onChanged,
39 : this.onImport,
40 : this.subtitle,
41 : this.isDisabled = false,
42 : this.children = const [],
43 : this.accountTitle,
44 : });
45 :
46 2 : @override
47 : Widget build(BuildContext context) {
48 2 : final textTheme = context.textTheme;
49 2 : return Card(
50 4 : margin: EdgeInsets.symmetric(vertical: ThemeHelper.getIndent()),
51 2 : child: Padding(
52 4 : padding: EdgeInsets.all(ThemeHelper.getIndent(2)),
53 2 : child: LayoutBuilder(
54 4 : builder: (context, constraints) => Column(
55 2 : crossAxisAlignment: AppDesign.getAlignment(),
56 2 : children: [
57 6 : Text(title, style: textTheme.titleMedium),
58 4 : if (subtitle != null) Text(subtitle!),
59 2 : ThemeHelper.hIndent,
60 2 : InputWrapper(
61 : type: NamedInputType.accountSelector,
62 6 : title: accountTitle ?? AppLocale.labels.account,
63 : isRequired: true,
64 8 : value: target.appAccount != null ? state.getByUuid(target.appAccount!) : null,
65 0 : onChange: (value) {
66 0 : target.appAccount = value?.uuid;
67 0 : onChanged();
68 : },
69 2 : state: state,
70 2 : width: constraints.maxWidth,
71 : ),
72 2 : InputWrapper(
73 : type: NamedInputType.budgetSelector,
74 4 : title: AppLocale.labels.integrationDefaultBudgetCategory,
75 : isRequired: true,
76 8 : value: target.category != null ? state.getByUuid(target.category!) : null,
77 0 : onChange: (value) {
78 0 : target.category = value?.uuid;
79 0 : onChanged();
80 : },
81 2 : state: state,
82 2 : width: constraints.maxWidth,
83 : ),
84 2 : if (onImport != null)
85 2 : InputWrapper(
86 : type: NamedInputType.dateSelector,
87 4 : title: AppLocale.labels.integrationDateFrom,
88 4 : value: target.from,
89 0 : onChange: (value) {
90 0 : target.from = value ?? target.from;
91 0 : onChanged();
92 : },
93 : ),
94 2 : ...children,
95 4 : if (onImport != null) ...[
96 : ThemeHelper.hIndent,
97 2 : FullSizedButtonWidget(
98 : icon: Icons.download,
99 2 : onPressed: onImport!,
100 4 : title: AppLocale.labels.integrationImport,
101 2 : isDisabled: isDisabled,
102 : ),
103 : ],
104 : ],
105 : ),
106 : ),
107 : ),
108 : );
109 : }
110 : }
|