forked from nombrekeff/super_tree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex_node_example.dart
More file actions
282 lines (264 loc) · 9.4 KB
/
Copy pathcomplex_node_example.dart
File metadata and controls
282 lines (264 loc) · 9.4 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import 'package:flutter/material.dart';
import 'package:super_tree/super_tree.dart';
enum TaskPriority { low, medium, high }
enum TaskStatus { todo, inProgress, done }
class TaskItem {
final String title;
final String assignee;
final TaskPriority priority;
TaskStatus status;
TaskItem({
required this.title,
required this.assignee,
required this.priority,
this.status = TaskStatus.todo,
});
}
class ComplexNodeExample extends StatefulWidget {
const ComplexNodeExample({super.key});
@override
State<ComplexNodeExample> createState() => _ComplexNodeExampleState();
}
class _ComplexNodeExampleState extends State<ComplexNodeExample> {
late TreeController<TaskItem> _controller;
@override
void initState() {
super.initState();
_controller = TreeController<TaskItem>(
roots: [
TreeNode(
id: 'epic_1',
data: TaskItem(
title: 'Website Redesign',
assignee: 'Alice',
priority: TaskPriority.high,
status: TaskStatus.inProgress,
),
isExpanded: true,
children: [
TreeNode(
id: 'story_1_1',
data: TaskItem(
title: 'Design Mockups',
assignee: 'Bob',
priority: TaskPriority.high,
status: TaskStatus.done,
),
),
TreeNode(
id: 'story_1_2',
data: TaskItem(
title: 'Implement Header',
assignee: 'Charlie',
priority: TaskPriority.medium,
status: TaskStatus.inProgress,
),
isExpanded: true,
children: [
TreeNode(
id: 'task_1_2_1',
data: TaskItem(
title: 'Add Logo',
assignee: 'Charlie',
priority: TaskPriority.low,
status: TaskStatus.done,
),
),
TreeNode(
id: 'task_1_2_2',
data: TaskItem(
title: 'Navigation Menu',
assignee: 'Charlie',
priority: TaskPriority.high,
status: TaskStatus.todo,
),
),
],
),
],
),
TreeNode(
id: 'epic_2',
data: TaskItem(
title: 'Q2 Marketing Campaign',
assignee: 'Diana',
priority: TaskPriority.medium,
),
children: [
TreeNode(
id: 'story_2_1',
data: TaskItem(
title: 'Social Media Assets',
assignee: 'Eve',
priority: TaskPriority.medium,
),
),
],
),
],
);
}
Color _getPriorityColor(TaskPriority priority) {
switch (priority) {
case TaskPriority.low:
return Colors.green;
case TaskPriority.medium:
return Colors.orange;
case TaskPriority.high:
return Colors.red;
}
}
IconData _getStatusIcon(TaskStatus status) {
switch (status) {
case TaskStatus.todo:
return Icons.radio_button_unchecked;
case TaskStatus.inProgress:
return Icons.timelapse;
case TaskStatus.done:
return Icons.check_circle;
}
}
Color _getStatusColor(TaskStatus status) {
switch (status) {
case TaskStatus.todo:
return Colors.grey;
case TaskStatus.inProgress:
return Colors.blue;
case TaskStatus.done:
return Colors.green;
}
}
@override
Widget build(BuildContext context) {
final ColorScheme scheme = Theme.of(context).colorScheme;
return Scaffold(
appBar: AppBar(title: const Text('Complex Node UI Example')),
body: Padding(
padding: const EdgeInsets.all(24.0),
child: Center(
child: Container(
constraints: const BoxConstraints(maxWidth: 800),
decoration: BoxDecoration(
border: Border.all(color: scheme.outlineVariant.withValues(alpha: 0.55)),
borderRadius: BorderRadius.circular(8),
),
child: SuperTreeView<TaskItem>(
controller: _controller,
style: TreeViewStyle(
indentAmount: 32.0,
selectedColor: scheme.secondaryContainer.withValues(alpha: 0.35),
hoverColor: scheme.surfaceContainerHigh.withValues(alpha: 0.8),
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
),
logic: const TreeViewConfig(expansionTrigger: ExpansionTrigger.tap),
prefixBuilder: (context, node) {
if (node.children.isEmpty) return const SizedBox(width: 24);
return Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Icon(
node.isExpanded ? Icons.remove_circle_outline : Icons.add_circle_outline,
color: scheme.onSurfaceVariant,
),
);
},
contentBuilder: (context, node, renameField) {
final data = node.data;
final Color titleColor = data.status == TaskStatus.done
? scheme.onSurface.withValues(alpha: 0.6)
: scheme.onSurface;
return Container(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
decoration: BoxDecoration(
color: scheme.surfaceContainerHigh,
border: Border.all(color: scheme.outlineVariant.withValues(alpha: 0.5)),
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.18),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: Row(
children: [
// Status Icon
InkWell(
onTap: () {
setState(() {
if (data.status == TaskStatus.todo) {
data.status = TaskStatus.inProgress;
} else if (data.status == TaskStatus.inProgress) {
data.status = TaskStatus.done;
} else {
data.status = TaskStatus.todo;
}
});
},
child: Icon(
_getStatusIcon(data.status),
color: _getStatusColor(data.status),
size: 20,
),
),
const SizedBox(width: 12),
// Title
Expanded(
child:
renameField ??
Text(
data.title,
maxLines: 1,
overflow: TextOverflow.clip,
style: TextStyle(
fontSize: 16,
fontWeight: node.children.isNotEmpty
? FontWeight.bold
: FontWeight.normal,
decoration: data.status == TaskStatus.done
? TextDecoration.lineThrough
: null,
color: titleColor,
),
),
),
// Priority Chip
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: _getPriorityColor(data.priority).withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Text(
data.priority.name.toUpperCase(),
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
color: _getPriorityColor(data.priority),
),
),
),
const SizedBox(width: 12),
// Assignee Avatar
CircleAvatar(
radius: 14,
backgroundColor: scheme.secondaryContainer,
child: Text(
data.assignee[0],
style: TextStyle(fontSize: 12, color: scheme.onSecondaryContainer),
),
),
const SizedBox(width: 8),
// More actions menu
Icon(Icons.more_vert, size: 20, color: scheme.onSurfaceVariant),
],
),
);
},
),
),
),
),
);
}
}