-
Notifications
You must be signed in to change notification settings - Fork 6
/
search-delegate.dart
95 lines (86 loc) · 2.25 KB
/
search-delegate.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
//Implementing search functionality using search delegate in flutter.
class TextBox extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: TextField(
cursorHeight: 20,
decoration: InputDecoration(
hintText: 'Search in mail',
border: InputBorder.none,
),
onTap: () {
showSearch(context: context, delegate: Datasearch());
},
),
);
}
}
class Datasearch extends SearchDelegate<String> {
final names = [
'deepa',
'deepak',
'sugarcosmetics',
'balram',
'linkedln',
'banglore',
'balram0698@gmail.com',
'pandey.deepa@tcs.com',
'sugarcosmetics@gmail.com',
'pandeydeepak821@gmail.com',
'balram.rathore@tcs.com',
];
final recentSearches = [
'pandey.deepa@tcs.com',
'sugarcosmetics@gmail.com',
'pandeydeepak821@gmail.com',
'balram0698@gmail.com'
];
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
icon: Icon(Icons.mic),
onPressed: () {},
)
];
}
@override
Widget buildLeading(BuildContext context) {
return IconButton(
icon: AnimatedIcon(
icon: AnimatedIcons.menu_arrow,
progress: transitionAnimation,
),
onPressed: () {
close(context, null);
},
);
}
@override
Widget buildResults(BuildContext context) {
throw UnimplementedError();
}
@override
Widget buildSuggestions(BuildContext context) {
final suggestionList = query.isEmpty
? recentSearches
: names.where((element) => element.startsWith(query)).toList();
return ListView.builder(
itemBuilder: (context, index) => ListTile(
leading: Icon(Icons.person_search),
title: RichText(
text: TextSpan(
text: suggestionList[index].substring(0, query.length),
style:
TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
children: [
TextSpan(
text: suggestionList[index].substring(query.length),
style: TextStyle(color: Colors.grey))
])),
),
itemCount: suggestionList.length,
);
}
}