-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
custom.dart
100 lines (90 loc) · 2.73 KB
/
custom.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
// Custom Suggestions
import 'package:example/user_model.dart';
import 'package:flutter/material.dart';
import 'package:searchfield/searchfield.dart';
import 'user_data.dart';
class UserSelect extends StatefulWidget {
const UserSelect({super.key});
@override
State<UserSelect> createState() => _UserSelectState();
}
class _UserSelectState extends State<UserSelect> {
final List<UserModel> users = [];
@override
void initState() {
super.initState();
users_data.forEach((element) {
users.add(UserModel.fromJson(element));
});
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: SearchField<UserModel>(
maxSuggestionsInViewPort: 5,
itemHeight: 80,
hint: 'Search for users',
suggestionsDecoration: SuggestionDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(8.0),
bottomRight: Radius.circular(8),
),
border: Border.all(
color: Colors.grey.withOpacity(0.5),
),
),
// initialValue: SearchFieldListItem<UserModel>(
// users[2].name,
// child: Container(
// color: Colors.red,
// width: 100,
// alignment: Alignment.center,
// child: Text(
// users[2].name,
// style: TextStyle(color: Colors.white),
// ),
// ),
// ),
suggestionItemDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
shape: BoxShape.rectangle,
border: Border.all(
color: Colors.transparent,
style: BorderStyle.solid,
width: 1.0)),
searchInputDecoration: SearchInputDecoration(
filled: true,
fillColor: Colors.grey.withOpacity(0.2),
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.white,
width: 2.0,
),
borderRadius: BorderRadius.circular(8.0),
),
border: OutlineInputBorder(),
),
marginColor: Colors.grey.shade300,
suggestions: users
.map((e) => SearchFieldListItem<UserModel>(e.name,
child: UserTile(user: e)))
.toList(),
),
);
}
}
class UserTile extends StatelessWidget {
final UserModel user;
const UserTile({Key? key, required this.user}) : super(key: key);
@override
Widget build(BuildContext context) {
return ListTile(
leading: CircleAvatar(
backgroundImage: NetworkImage(user.avatar),
),
title: Text(user.name),
subtitle: Text(user.email),
);
}
}