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
|
import 'package:flutter/material.dart';
import 'package:device_apps/device_apps.dart';
import 'AppList.dart';
class _SearchableAppListState extends State<SearchableAppList> {
final _inputController = TextEditingController();
void initState() {
super.initState();
}
void dispose() {
_inputController.dispose();
super.dispose();
}
void reset() {
_inputController.clear();
}
int _appSorter(Application a, Application b) {
return a.appName.toLowerCase().compareTo(b.appName.toLowerCase());
}
bool _filterApp(Application a) {
var searchTerm = _inputController.text;
return a.appName.toLowerCase().contains(searchTerm.toLowerCase());
}
Widget getIcon(IconData icon, { Color color }) {
var inputIconSize = 16.0;
return Icon(icon, color: color, size: inputIconSize);
}
@override
Widget build(BuildContext ctx) {
ThemeData theme = Theme.of(context);
List<Application> results = widget.appList
.where(_filterApp)
.toList();
results.sort(_appSorter);
return Column(
children: [
Container(
height: 30,
child: Align(
alignment: Alignment.topRight,
child: TextField(
enableSuggestions: false,
controller: _inputController,
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
hintStyle: TextStyle(color: Color(0x88D8DEE9)),
hintText: 'Search',
suffix: IconButton(
icon: getIcon(Icons.close, color: Colors.red[400]),
onPressed: reset,
),
),
)
),
),
Expanded(child: AppList(
appList: results,
openApp: widget.openApp,
openOptionsMenu: widget.openOptionsMenu,
)),
],
);
}
}
class SearchableAppList extends StatefulWidget {
List<Application> appList;
void Function(Application) openApp;
void Function(Application) openOptionsMenu;
SearchableAppList({ this.appList, this.openApp, this.openOptionsMenu }): super();
@override
_SearchableAppListState createState() => _SearchableAppListState();
}
|