forked from doonfrs/pluto_grid_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
188 lines (178 loc) · 5.14 KB
/
main.dart
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import 'package:flutter/material.dart';
import 'package:pluto_grid_plus/pluto_grid_plus.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PlutoGrid Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const PlutoGridExamplePage(),
);
}
}
/// PlutoGrid Example
//
/// For more examples, go to the demo web link on the github below.
class PlutoGridExamplePage extends StatefulWidget {
const PlutoGridExamplePage({super.key});
@override
State<PlutoGridExamplePage> createState() => _PlutoGridExamplePageState();
}
class _PlutoGridExamplePageState extends State<PlutoGridExamplePage> {
final List<PlutoColumn> columns = <PlutoColumn>[
PlutoColumn(
title: 'Id',
field: 'id',
type: PlutoColumnType.text(),
),
PlutoColumn(
title: 'Name',
field: 'name',
type: PlutoColumnType.text(),
),
PlutoColumn(
title: 'Age',
field: 'age',
type: PlutoColumnType.number(),
),
PlutoColumn(
title: 'Role',
field: 'role',
type: PlutoColumnType.select(<String>[
'Programmer',
'Designer',
'Owner',
]),
),
PlutoColumn(
title: 'Role 2',
field: 'role2',
type: PlutoColumnType.select(
<String>[
'Programmer',
'Designer',
'Owner',
],
builder: (item) {
return Row(children: [
Icon(item == 'Programmer' ? Icons.code : Icons.design_services),
const SizedBox(width: 8),
Text(item),
]);
},
),
),
PlutoColumn(
title: 'Joined',
field: 'joined',
type: PlutoColumnType.date(),
),
PlutoColumn(
title: 'Working time',
field: 'working_time',
type: PlutoColumnType.time(),
),
PlutoColumn(
title: 'salary',
field: 'salary',
type: PlutoColumnType.currency(),
footerRenderer: (rendererContext) {
return PlutoAggregateColumnFooter(
rendererContext: rendererContext,
formatAsCurrency: true,
type: PlutoAggregateColumnType.sum,
format: '#,###',
alignment: Alignment.center,
titleSpanBuilder: (text) {
return [
const TextSpan(
text: 'Sum',
style: TextStyle(color: Colors.red),
),
const TextSpan(text: ' : '),
TextSpan(text: text),
];
},
);
},
),
];
final List<PlutoRow> rows = [
PlutoRow(
cells: {
'id': PlutoCell(value: 'user1'),
'name': PlutoCell(value: 'Mike'),
'age': PlutoCell(value: 20),
'role': PlutoCell(value: 'Programmer'),
'role2': PlutoCell(value: 'Programmer'),
'joined': PlutoCell(value: '2021-01-01'),
'working_time': PlutoCell(value: '09:00'),
'salary': PlutoCell(value: 300),
},
),
PlutoRow(
cells: {
'id': PlutoCell(value: 'user2'),
'name': PlutoCell(value: 'Jack'),
'age': PlutoCell(value: 25),
'role': PlutoCell(value: 'Designer'),
'role2': PlutoCell(value: 'Designer'),
'joined': PlutoCell(value: '2021-02-01'),
'working_time': PlutoCell(value: '10:00'),
'salary': PlutoCell(value: 400),
},
),
PlutoRow(
cells: {
'id': PlutoCell(value: 'user3'),
'name': PlutoCell(value: 'Suzi'),
'age': PlutoCell(value: 40),
'role': PlutoCell(value: 'Owner'),
'role2': PlutoCell(value: 'Owner'),
'joined': PlutoCell(value: '2021-03-01'),
'working_time': PlutoCell(value: '11:00'),
'salary': PlutoCell(value: 700),
},
),
];
/// columnGroups that can group columns can be omitted.
final List<PlutoColumnGroup> columnGroups = [
PlutoColumnGroup(title: 'Id', fields: ['id'], expandedColumn: true),
PlutoColumnGroup(title: 'User information', fields: ['name', 'age']),
PlutoColumnGroup(title: 'Status', children: [
PlutoColumnGroup(title: 'A', fields: ['role'], expandedColumn: true),
PlutoColumnGroup(
title: 'Etc.', fields: ['joined', 'working_time', 'role2']),
]),
];
/// [PlutoGridStateManager] has many methods and properties to dynamically manipulate the grid.
/// You can manipulate the grid dynamically at runtime by passing this through the [onLoaded] callback.
late final PlutoGridStateManager stateManager;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: const EdgeInsets.all(15),
child: PlutoGrid(
columns: columns,
rows: rows,
columnGroups: columnGroups,
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
stateManager.setShowColumnFilter(true);
},
onChanged: (PlutoGridOnChangedEvent event) {
print(event);
},
configuration: const PlutoGridConfiguration(),
),
),
);
}
}