Repository navigation
Expand file tree
/
Copy pathexample.dart
More file actions
210 lines (199 loc) · 6.15 KB
/
Copy pathexample.dart
File metadata and controls
210 lines (199 loc) · 6.15 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
import 'package:flutter/material.dart';
import 'package:slideable/slideable.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Slideable Widget',
home: Home(),
);
}
}
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
// This is used to monitor the item index in the list, and later used to closeup or leave open the slide.
int resetSlideIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Class List"),
),
body: ListView.separated(
itemCount: _classList.length,
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 20,
),
itemBuilder: (context, index) {
final Map<String, dynamic> student = _classList[index];
return GestureDetector(
onLongPressDown: (val) {
// This allows you the time taken for a user to slide upon the widget in the list.
// NB: Using the onTap or onHorizontalDragStart seemed to have caused a seizure in the widget, hence my resulting to onLongPressDown
setState(() {
// This updates the widget, and inturn rebuilds it, thereby notifying the Slidable widget to close an already slide item
resetSlideIndex = index;
});
},
child: _listItem(
context: context,
student: student,
index: index,
resetSlide: index != resetSlideIndex,
// Reverse engineering the notion, meaning the Slidable widget will close all slid item, except one with false, i.e the currently slide item
),
);
},
separatorBuilder: (context, index) => const SizedBox(height: 10),
),
);
}
Slideable _listItem({
required BuildContext context,
required Map<String, dynamic> student,
required int index,
required bool resetSlide,
}) {
return Slideable(
resetSlide: resetSlide,
items: <ActionItems>[
ActionItems(
icon: const Icon(
Icons.thumb_up,
color: Colors.blue,
),
onPress: () => _likeUser(student["name"]),
backgroudColor: Colors.transparent,
),
ActionItems(
icon: const Icon(
Icons.delete,
color: Colors.red,
),
onPress: () => _deleteUser(student["name"]),
backgroudColor: Colors.transparent,
),
],
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 12,
),
decoration: BoxDecoration(
color: const Color.fromARGB(255, 214, 214, 214),
border: Border.all(
width: 1,
color: const Color.fromARGB(124, 158, 158, 158),
),
borderRadius: BorderRadius.circular(10),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.grey[350],
shape: BoxShape.circle,
border: Border.all(
width: 1,
color: Colors.white,
),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.network(
student["img"],
fit: BoxFit.cover,
),
),
),
const SizedBox(
width: 5,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Name",
style: TextStyle(
color: Colors.grey,
fontSize: 12,
fontWeight: FontWeight.w800,
),
),
const SizedBox(height: 2),
Text(
student["name"],
style: const TextStyle(
fontWeight: FontWeight.w500,
),
),
],
),
),
Text(
"#${index + 1}",
style: const TextStyle(
fontWeight: FontWeight.w500,
),
),
],
),
),
);
}
void _deleteUser(String user) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("$user, will be deleted."),
backgroundColor: Colors.grey[450],
),
);
}
void _likeUser(String user) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("You gave $user a thumbs up, pretty cool 🥰"),
backgroundColor: Colors.grey[450],
),
);
}
final List<Map<String, dynamic>> _classList = [
{
"name": "Ikwegbu George",
"img":
"https://images.pexels.com/photos/2379429/pexels-photo-2379429.jpeg?auto=compress&cs=tinysrgb&w=1600",
},
{
"name": "Phoebe Pelumi",
"img":
"https://images.pexels.com/photos/3986672/pexels-photo-3986672.jpeg?auto=compress&cs=tinysrgb&w=1600&lazy=load",
},
{
"name": "James Mike",
"img":
"https://images.pexels.com/photos/11828983/pexels-photo-11828983.jpeg?auto=compress&cs=tinysrgb&w=1600&lazy=load",
},
{
"name": "Abigail Ezinne",
"img":
"https://images.pexels.com/photos/3030252/pexels-photo-3030252.jpeg?auto=compress&cs=tinysrgb&w=1600&lazy=load",
},
{
"name": "Chioma Chinedu",
"img":
"https://images.pexels.com/photos/4491630/pexels-photo-4491630.jpeg?auto=compress&cs=tinysrgb&w=1600",
},
];
}