/
list_tile_example.dart
150 lines (142 loc) · 4.17 KB
/
list_tile_example.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
import 'package:drag_and_drop_lists/drag_and_drop_lists.dart';
import 'package:example/navigation_drawer.dart';
import 'package:flutter/material.dart';
class ListTileExample extends StatefulWidget {
const ListTileExample({Key? key}) : super(key: key);
@override
State createState() => _ListTileExample();
}
class _ListTileExample extends State<ListTileExample> {
late List<DragAndDropList> _contents;
@override
void initState() {
super.initState();
_contents = List.generate(4, (index) {
return DragAndDropList(
header: Column(
children: <Widget>[
ListTile(
title: Text(
'Header $index',
),
subtitle: Text('Header $index subtitle'),
),
const Divider(),
],
),
footer: Column(
children: <Widget>[
const Divider(),
ListTile(
title: Text(
'Footer $index',
),
subtitle: Text('Footer $index subtitle'),
),
],
),
children: <DragAndDropItem>[
DragAndDropItem(
child: ListTile(
title: Text(
'Sub $index.1',
),
trailing: const Icon(Icons.access_alarm),
),
),
DragAndDropItem(
child: ListTile(
title: Text(
'Sub $index.2',
),
trailing: const Icon(Icons.alarm_off),
),
),
DragAndDropItem(
child: ListTile(
title: Text(
'Sub $index.3',
),
trailing: const Icon(Icons.alarm_on),
),
),
],
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('List Tiles'),
),
drawer: const NavigationDrawer(),
body: DragAndDropLists(
children: _contents,
onItemReorder: _onItemReorder,
onListReorder: _onListReorder,
listGhost: Padding(
padding: const EdgeInsets.symmetric(vertical: 30.0),
child: Center(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 40.0, horizontal: 100.0),
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.circular(7.0),
),
child: const Icon(Icons.add_box),
),
),
),
listPadding: const EdgeInsets.symmetric(horizontal: 5, vertical: 10),
contentsWhenEmpty: Row(
children: <Widget>[
const Expanded(
child: Padding(
padding: EdgeInsets.only(left: 40, right: 10),
child: Divider(),
),
),
Text(
'Empty List',
style: TextStyle(
color: Theme.of(context).textTheme.caption!.color,
fontStyle: FontStyle.italic),
),
const Expanded(
child: Padding(
padding: EdgeInsets.only(left: 20, right: 40),
child: Divider(),
),
),
],
),
listDecoration: BoxDecoration(
color: Theme.of(context).canvasColor,
borderRadius: const BorderRadius.all(Radius.circular(6.0)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 3,
offset: const Offset(0, 3), // changes position of shadow
),
],
),
),
);
}
_onItemReorder(
int oldItemIndex, int oldListIndex, int newItemIndex, int newListIndex) {
setState(() {
var movedItem = _contents[oldListIndex].children.removeAt(oldItemIndex);
_contents[newListIndex].children.insert(newItemIndex, movedItem);
});
}
_onListReorder(int oldListIndex, int newListIndex) {
setState(() {
var movedList = _contents.removeAt(oldListIndex);
_contents.insert(newListIndex, movedList);
});
}
}