From 15a7f9f962788c5284bb019b7e4775795b0a9302 Mon Sep 17 00:00:00 2001 From: Aunali321 Date: Tue, 2 Aug 2022 15:56:37 +0530 Subject: [PATCH] feat: wip searchbar in appselector. --- lib/ui/screens/app_selector_screen.dart | 61 ++++++++++++++++++----- lib/ui/widgets/installed_app_item.dart | 50 ++++++++++++++----- lib/ui/widgets/search_bar.dart | 64 +++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 22 deletions(-) create mode 100644 lib/ui/widgets/search_bar.dart diff --git a/lib/ui/screens/app_selector_screen.dart b/lib/ui/screens/app_selector_screen.dart index 6b659a5f..14555505 100644 --- a/lib/ui/screens/app_selector_screen.dart +++ b/lib/ui/screens/app_selector_screen.dart @@ -1,6 +1,7 @@ import 'package:device_apps/device_apps.dart'; import 'package:flutter/material.dart'; import 'package:revanced_manager_flutter/ui/widgets/installed_app_item.dart'; +import 'package:revanced_manager_flutter/ui/widgets/search_bar.dart'; class AppSelectorScreen extends StatefulWidget { const AppSelectorScreen({Key? key}) : super(key: key); @@ -11,6 +12,7 @@ class AppSelectorScreen extends StatefulWidget { class _AppSelectorScreenState extends State { List apps = []; + String query = 'yout'; void getApps() async { apps = await DeviceApps.getInstalledApplications(); @@ -27,17 +29,54 @@ class _AppSelectorScreenState extends State { Widget build(BuildContext context) { return Scaffold( body: SafeArea( - child: apps.isEmpty - ? const Center(child: CircularProgressIndicator()) - : ListView.builder( - itemCount: apps.length, - itemBuilder: (context, index) { - return InstalledAppItem( - name: apps[index].appName, - pkgName: apps[index].packageName, - ); - }, - ), + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0), + child: Column( + children: [ + SearchBar(), + if (query.isEmpty || query.length < 2) + apps.isEmpty + ? const Center( + child: CircularProgressIndicator(), + ) + : Expanded( + child: ListView.builder( + itemCount: apps.length, + itemBuilder: (context, index) { + return InstalledAppItem( + name: apps[index].appName, + pkgName: apps[index].packageName, + isSelected: false, + ); + }, + ), + ), + if (query.isNotEmpty) + apps.isEmpty + ? const Center( + child: Text('No apps found'), + ) + : Expanded( + child: ListView.builder( + itemCount: apps.length, + itemBuilder: (context, index) { + if (apps[index].appName.toLowerCase().contains( + query.toLowerCase(), + )) { + return InstalledAppItem( + name: apps[index].appName, + pkgName: apps[index].packageName, + isSelected: false, + ); + } else { + return SizedBox(); + } + }, + ), + ), + ], + ), + ), ), ); } diff --git a/lib/ui/widgets/installed_app_item.dart b/lib/ui/widgets/installed_app_item.dart index d1fa7001..f82a9e9f 100644 --- a/lib/ui/widgets/installed_app_item.dart +++ b/lib/ui/widgets/installed_app_item.dart @@ -1,19 +1,28 @@ import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:revanced_manager_flutter/constants.dart'; -class InstalledAppItem extends StatelessWidget { +class InstalledAppItem extends StatefulWidget { final String name; final String pkgName; + bool isSelected = false; - const InstalledAppItem({ + InstalledAppItem({ Key? key, required this.name, required this.pkgName, + required this.isSelected, }) : super(key: key); + @override + State createState() => _InstalledAppItemState(); +} + +class _InstalledAppItemState extends State { @override Widget build(BuildContext context) { return Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0), + padding: const EdgeInsets.symmetric(vertical: 4.0), child: Container( padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 12.0), decoration: BoxDecoration( @@ -23,16 +32,35 @@ class InstalledAppItem extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(name), - Text(pkgName), - ], + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + widget.name, + maxLines: 2, + overflow: TextOverflow.visible, + style: GoogleFonts.inter( + fontSize: 16, + fontWeight: FontWeight.w500, + ), + ), + const SizedBox(height: 4), + Text( + widget.pkgName, + style: robotoTextStyle, + ), + ], + ), ), Checkbox( - value: false, - onChanged: (val) {}, + value: widget.isSelected, + onChanged: (val) { + setState(() { + widget.isSelected = val!; + Navigator.pop(context); + }); + }, ), ], ), diff --git a/lib/ui/widgets/search_bar.dart b/lib/ui/widgets/search_bar.dart new file mode 100644 index 00000000..3722c265 --- /dev/null +++ b/lib/ui/widgets/search_bar.dart @@ -0,0 +1,64 @@ +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; + +class SearchBar extends StatefulWidget { + const SearchBar({ + Key? key, + }) : super(key: key); + + @override + State createState() => _SearchBarState(); +} + +class _SearchBarState extends State { + @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), + border: Border.all( + color: const Color(0xff1B222B), + width: 1, + ), + ), + child: Row( + children: [ + Expanded( + child: TextField( + onSubmitted: (value) {}, + decoration: InputDecoration( + fillColor: Colors.blueGrey[700], + filled: true, + contentPadding: const EdgeInsets.all(12.0), + hintText: 'Search applications', + hintStyle: GoogleFonts.poppins( + color: Colors.white, + fontWeight: FontWeight.w400, + ), + prefixIcon: const Icon( + Icons.search, + color: Colors.white, + size: 24.0, + ), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: BorderSide.none, + ), + ), + style: GoogleFonts.poppins( + color: Colors.white, + fontWeight: FontWeight.w400, + fontSize: 16, + ), + ), + ), + ], + ), + ); + } +}