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
|
import 'package:flutter/material.dart';
import 'package:device_apps/device_apps.dart';
import 'AppList.dart';
class _SearchableAppListState extends State<SearchableAppList> {
String _searchTerm = '';
void onInput(String str) {
setState(() { _searchTerm = str; });
}
int _appSorter(Application a, Application b) {
return a.appName.toLowerCase().compareTo(b.appName.toLowerCase());
}
bool _filterApp(Application a) {
return a.appName.toLowerCase().contains(_searchTerm.toLowerCase()) ||
a.packageName.toLowerCase().contains(_searchTerm.toLowerCase());
}
@override
Widget build(BuildContext ctx) {
return Column(
children: [
Container(
height: 30,
child: TextField(
onChanged: onInput,
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Search',
),
),
),
Expanded(child: FutureBuilder(
future: widget.appListF,
builder: (ctx, AsyncSnapshot<List<Application>> snap) {
if (!snap.hasData) {
return Text('Loading...');
}
List<Application> results = snap.data
.where(_filterApp)
.toList();
results.sort(_appSorter);
return AppList(
appList: results,
openApp: widget.openApp,
openOptionsMenu: widget.openOptionsMenu,
);
}
)),
],
);
}
}
class SearchableAppList extends StatefulWidget {
Future<List<Application>> appListF;
void Function(Application) openApp;
void Function(Application) openOptionsMenu;
SearchableAppList({ this.appListF, this.openApp, this.openOptionsMenu }): super();
@override
_SearchableAppListState createState() => _SearchableAppListState();
}
|