feat: fully working search bar.

This commit is contained in:
Aunali321 2022-08-02 18:41:29 +05:30
parent 15a7f9f962
commit 0b58ce3dca
3 changed files with 18 additions and 10 deletions

View File

@ -12,7 +12,7 @@ class AppSelectorScreen extends StatefulWidget {
class _AppSelectorScreenState extends State<AppSelectorScreen> {
List<Application> apps = [];
String query = 'yout';
String query = '';
void getApps() async {
apps = await DeviceApps.getInstalledApplications();
@ -30,10 +30,16 @@ class _AppSelectorScreenState extends State<AppSelectorScreen> {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0),
padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 12.0),
child: Column(
children: [
SearchBar(),
SearchBar(
onQueryChanged: (searchQuery) {
setState(() {
query = searchQuery;
});
},
),
if (query.isEmpty || query.length < 2)
apps.isEmpty
? const Center(
@ -43,6 +49,8 @@ class _AppSelectorScreenState extends State<AppSelectorScreen> {
child: ListView.builder(
itemCount: apps.length,
itemBuilder: (context, index) {
//sort alphabetically
apps.sort((a, b) => a.appName.compareTo(b.appName));
return InstalledAppItem(
name: apps[index].appName,
pkgName: apps[index].packageName,
@ -60,6 +68,7 @@ class _AppSelectorScreenState extends State<AppSelectorScreen> {
child: ListView.builder(
itemCount: apps.length,
itemBuilder: (context, index) {
apps.sort((a, b) => a.appName.compareTo(b.appName));
if (apps[index].appName.toLowerCase().contains(
query.toLowerCase(),
)) {

View File

@ -37,7 +37,7 @@ class PatcherScreen extends StatelessWidget {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AppSelectorScreen()));
builder: (context) => const AppSelectorScreen()));
},
),
const SizedBox(height: 16),

View File

@ -2,10 +2,13 @@ import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class SearchBar extends StatefulWidget {
const SearchBar({
SearchBar({
Key? key,
required this.onQueryChanged,
}) : super(key: key);
final Function(String) onQueryChanged;
@override
State<SearchBar> createState() => _SearchBarState();
}
@ -14,10 +17,6 @@ class _SearchBarState extends State<SearchBar> {
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(
vertical: 0.0,
horizontal: 0.0,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: const Color(0xff1B222B),
@ -30,7 +29,7 @@ class _SearchBarState extends State<SearchBar> {
children: [
Expanded(
child: TextField(
onSubmitted: (value) {},
onChanged: widget.onQueryChanged,
decoration: InputDecoration(
fillColor: Colors.blueGrey[700],
filled: true,