Skip to content

Commit 3ad13ae

Browse files
committed
Add package search and optimize list
1 parent 49564c2 commit 3ad13ae

File tree

1 file changed

+55
-12
lines changed

1 file changed

+55
-12
lines changed

lib/pages/main/package_list.dart

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ class PackageList extends ConsumerStatefulWidget {
2222

2323
class _PackageListState extends ConsumerState<PackageList> {
2424
bool _dragging = false;
25+
TextEditingController filterController = TextEditingController();
26+
27+
@override
28+
void dispose() {
29+
super.dispose();
30+
filterController.dispose();
31+
}
2532

2633
@override
2734
Widget build(BuildContext context) {
@@ -33,13 +40,32 @@ class _PackageListState extends ConsumerState<PackageList> {
3340
automaticallyImplyLeading: true,
3441
actions: [
3542
IconButton(
36-
onPressed: () async {
37-
final file = await openFile();
38-
if (file == null) return;
43+
onPressed: () async {
44+
final file = await openFile();
45+
if (file == null) return;
3946

40-
await uploadAndInstallAPK(file.path);
41-
},
42-
icon: const Icon(FluentIcons.arrow_upload_32_regular))
47+
await uploadAndInstallAPK(file.path);
48+
},
49+
icon: const Icon(
50+
FluentIcons.arrow_upload_32_regular,
51+
),
52+
),
53+
Padding(
54+
padding: const EdgeInsets.symmetric(horizontal: 8.0),
55+
child: ConstrainedBox(
56+
constraints: const BoxConstraints.tightFor(width: 200),
57+
child: TextField(
58+
autocorrect: false,
59+
enableSuggestions: false,
60+
decoration: const InputDecoration(hintText: "Search"),
61+
controller: filterController,
62+
onChanged: (s) => setState(() {}),
63+
),
64+
),
65+
),
66+
const SizedBox(
67+
width: 25,
68+
),
4369
],
4470
),
4571
body: ADBQueueIndicator(
@@ -63,12 +89,26 @@ class _PackageListState extends ConsumerState<PackageList> {
6389
});
6490
},
6591
child: packageListFuture.when(
66-
data: (packageList) => ListView.separated(
67-
itemBuilder: (c, i) => itemBuilder(c, i, packageList),
68-
itemCount: packageList.length,
69-
shrinkWrap: true,
70-
separatorBuilder: (context, index) => const Divider(),
71-
),
92+
data: (packageList) {
93+
final filteredList = packageList
94+
.where((x) => x
95+
.toLowerCase()
96+
.contains(filterController.text.toLowerCase()))
97+
.toList();
98+
99+
return ListView.separated(
100+
itemBuilder: (c, i) => itemBuilder(c, i, filteredList),
101+
itemCount: filteredList.length,
102+
shrinkWrap: true,
103+
separatorBuilder: (context, index) => const Divider(),
104+
addAutomaticKeepAlives: true,
105+
findChildIndexCallback: (Key key) {
106+
var index =
107+
filteredList.indexOf((key as ValueKey<String>).value);
108+
if (index == -1) return null;
109+
return index;
110+
});
111+
},
72112
error: (error, stackTrace) {
73113
debugPrint(error.toString());
74114
debugPrint(stackTrace.toString());
@@ -94,6 +134,7 @@ class _PackageListState extends ConsumerState<PackageList> {
94134

95135
return packageMetadataFuture.when(
96136
data: (packageMetadata) => ListTile(
137+
key: ValueKey(packageId),
97138
title: Text(packageMetadata.packageName),
98139
subtitle:
99140
Text("${packageMetadata.packageId} - ${packageMetadata.version}"),
@@ -117,10 +158,12 @@ class _PackageListState extends ConsumerState<PackageList> {
117158
),
118159
),
119160
error: (error, stackTrace) => ListTile(
161+
key: ValueKey(packageId),
120162
title: Text(packageId),
121163
subtitle: Text("Suffered error: $error"),
122164
),
123165
loading: () => ListTile(
166+
key: ValueKey(packageId),
124167
title: Text(packageId),
125168
leading: const CircularProgressIndicator(),
126169
),

0 commit comments

Comments
 (0)