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/storage/app_data.dart';
5 : import 'package:app_finance/design/form/list_selector_item.dart';
6 : import 'package:app_finance/design/form/list_selector.dart';
7 : import 'package:app_finance/design/generic/base_line_widget.dart';
8 : import 'package:material_ui/material_ui.dart';
9 :
10 : class ListAccountSelectorItem extends ListSelectorItem {
11 : dynamic item;
12 :
13 1 : @override
14 2 : Widget build(context) => LayoutBuilder(builder: (_, constraints) {
15 1 : return BaseLineWidget(
16 2 : uuid: item.uuid ?? '',
17 2 : title: item.title ?? '',
18 2 : description: item.description ?? '',
19 2 : details: item.detailsFormatted ?? '',
20 : progress: 1.0,
21 2 : color: item.color ?? Colors.transparent,
22 2 : icon: item.icon ?? Icons.radio_button_unchecked_sharp,
23 2 : hidden: item.hidden ?? false,
24 2 : skip: item.skip ?? false,
25 1 : width: constraints.maxWidth,
26 : showDivider: false,
27 : );
28 : });
29 :
30 1 : @override
31 2 : Widget suggest(context) => LayoutBuilder(builder: (_, constraints) {
32 1 : return BaseLineWidget(
33 2 : uuid: item.uuid ?? '',
34 2 : title: item.title ?? '',
35 2 : description: item.description ?? '',
36 2 : details: item.detailsFormatted ?? '',
37 2 : progress: item.progress ?? 0.0,
38 2 : color: item.color ?? Colors.transparent,
39 2 : icon: item.icon ?? Icons.radio_button_unchecked_sharp,
40 2 : hidden: item.hidden ?? false,
41 2 : skip: item.skip ?? false,
42 1 : width: constraints.maxWidth,
43 : showDivider: false,
44 : );
45 : });
46 :
47 1 : @override
48 2 : String get id => item.uuid;
49 :
50 1 : @override
51 2 : String get name => item.title;
52 :
53 1 : ListAccountSelectorItem({
54 : required this.item,
55 : super.name = '',
56 : super.id = '',
57 : });
58 : }
59 :
60 : class ListAccountSelector<K extends ListAccountSelectorItem> extends ListSelector<ListAccountSelectorItem> {
61 : final AppData state;
62 : final double width;
63 :
64 1 : const ListAccountSelector({
65 : super.key,
66 : required this.state,
67 : required super.setState,
68 : required this.width,
69 : required super.hintText,
70 : super.options = const [],
71 : super.value,
72 : super.tooltip,
73 : super.withLabel,
74 1 : }) : super();
75 :
76 1 : @override
77 : List<ListAccountSelectorItem> get options {
78 2 : return super.options.isNotEmpty
79 1 : ? super.options
80 0 : : state.getList(AppDataType.accounts).map((item) => ListAccountSelectorItem(item: item)).toList();
81 : }
82 :
83 1 : @override
84 1 : ListSelectorState createState() => ListSelectorState<ListAccountSelector, ListAccountSelectorItem>();
85 : }
|