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:flutter/material.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 1 : width: constraints.maxWidth,
25 : showDivider: false,
26 : );
27 : });
28 :
29 1 : @override
30 2 : Widget suggest(context) => LayoutBuilder(builder: (_, constraints) {
31 1 : return BaseLineWidget(
32 2 : uuid: item.uuid ?? '',
33 2 : title: item.title ?? '',
34 2 : description: item.description ?? '',
35 2 : details: item.detailsFormatted ?? '',
36 2 : progress: item.progress ?? 0.0,
37 2 : color: item.color ?? Colors.transparent,
38 2 : icon: item.icon ?? Icons.radio_button_unchecked_sharp,
39 2 : hidden: item.hidden ?? false,
40 1 : width: constraints.maxWidth,
41 : showDivider: false,
42 : );
43 : });
44 :
45 1 : @override
46 2 : String get id => item.uuid;
47 :
48 1 : @override
49 2 : String get name => item.title;
50 :
51 1 : ListAccountSelectorItem({
52 : required this.item,
53 : super.name = '',
54 : super.id = '',
55 : });
56 : }
57 :
58 : class ListAccountSelector<K extends ListAccountSelectorItem> extends ListSelector<ListAccountSelectorItem> {
59 : final AppData state;
60 : final double width;
61 :
62 1 : const ListAccountSelector({
63 : super.key,
64 : required this.state,
65 : required super.setState,
66 : required this.width,
67 : required super.hintText,
68 : super.options = const [],
69 : super.value,
70 : super.tooltip,
71 : super.withLabel,
72 1 : }) : super();
73 :
74 1 : @override
75 : List<ListAccountSelectorItem> get options {
76 2 : return super.options.isNotEmpty
77 1 : ? super.options
78 0 : : state.getList(AppDataType.accounts).map((item) => ListAccountSelectorItem(item: item)).toList();
79 : }
80 :
81 1 : @override
82 1 : ListSelectorState createState() => ListSelectorState<ListAccountSelector, ListAccountSelectorItem>();
83 : }
|