-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic.dart
More file actions
137 lines (127 loc) · 3.92 KB
/
basic.dart
File metadata and controls
137 lines (127 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// ignore_for_file: deprecated_member_use
part of '../table.dart';
class BasicTableView extends StatefulWidget {
final String name;
const BasicTableView({
super.key,
this.name = 'Generic View',
});
@override
State<BasicTableView> createState() => _BasicTableViewState();
}
class _BasicTableViewState extends State<BasicTableView> {
List<Asset> _items = [];
int get _it => 14000;
@override
void initState() {
super.initState();
_items = List.generate(_it, (i) => _generateAsset(i));
}
Asset _generateAsset(int index) {
return Asset(
id: (index + 1).toString(),
name: (index == 2) ? "Asset asdasfasfasf ${index + 1}" : "Other Asset ${index + 1}",
plate: 'PLATE${index + 1} testestes',
vin: 'VIN${index + 1}',
mode: AssetMode.single,
kind: Category(id: (index + 1).toString(), name: 'Category ${index + 1}', kind: CategoryKind.asset),
activeTime: DateTime.now().toString(),
);
}
@override
Widget build(BuildContext context) {
return Layout(
body: ThemedTable<Asset>(
module: 'assets',
idLabel: "#ID",
idBuilder: (context, item) => item.id,
enableMultiSelectDialog: true,
multiSelectionEnabled: true,
idEnabled: true,
disablePaginator: false,
onIdTap: (item) {
debugPrint("Tapped on ${item.id}");
},
items: _items,
onShow: (context, item) async {
debugPrint("onShow tapped: $item");
},
onAdd: () async {
_items.add(_generateAsset(_items.length));
setState(() {});
},
onRefresh: () async {
_items = List.generate(_it, (i) => _generateAsset(i));
setState(() {});
},
onEdit: (context, item) async {
debugPrint("onEdit tapped: $item");
},
onDelete: (context, item) async {
_items.removeWhere((element) => element.id == item.id);
setState(() {});
},
onMultiDelete: (context, items) async {
List<String> pks = items.map((e) => e.id).toList();
_items.removeWhere((element) => pks.contains(element.id));
setState(() {});
return true;
},
columns: [
ThemedColumn(
labelText: 'Name',
valueBuilder: (context, item) => item.name,
richTextBuilder: (context, item) {
return [
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Padding(
padding: const EdgeInsets.only(right: 5),
child: Icon(
Icons.check_circle,
color: Colors.green,
size: 20,
),
),
),
TextSpan(
text: item.name,
style: Theme.of(context).textTheme.bodyMedium,
),
];
},
width: 200,
// cellColor: (item) => Colors.yellow,
cellTextColor: (item) => Colors.red,
onTap: (item) {
debugPrint("Tapped on ${item.name}");
},
),
ThemedColumn(
labelText: 'Name',
valueBuilder: (_, item) => item.name,
onTap: (item) {
debugPrint("Tapped on ${item.name}");
},
),
ThemedColumn(
labelText: 'Plate',
valueBuilder: (_, item) => item.plate ?? 'N/A',
),
ThemedColumn(
labelText: 'VIN',
valueBuilder: (_, item) => item.vin ?? 'N/A',
),
ThemedColumn(
labelText: 'Mode',
valueBuilder: (_, item) => item.mode?.name ?? 'N/A',
),
ThemedColumn(
labelText: 'Kind',
valueBuilder: (_, item) => item.kind?.name ?? 'N/A',
),
],
),
);
}
}