From 6fa25596981b0b9cb5f49533e88d3f2fb5a3cb1f Mon Sep 17 00:00:00 2001 From: Rahul Dev Garg <34365102+rahuldevgarg@users.noreply.github.com> Date: Wed, 13 Sep 2023 16:16:57 +0530 Subject: [PATCH] added search button in tenants selection --- .../mgramseva/lib/model/mdms/tenants.dart | 5 + .../mgramseva/lib/widgets/custom_app_bar.dart | 185 +++++++++++------- 2 files changed, 114 insertions(+), 76 deletions(-) diff --git a/frontend/mgramseva/lib/model/mdms/tenants.dart b/frontend/mgramseva/lib/model/mdms/tenants.dart index 0b7c2e215..d9ecce78c 100644 --- a/frontend/mgramseva/lib/model/mdms/tenants.dart +++ b/frontend/mgramseva/lib/model/mdms/tenants.dart @@ -58,6 +58,11 @@ class Tenants { factory Tenants.fromJson(Map json) => _$TenantsFromJson(json); + @override + String toString() { + return '$code'; + } + Map toJson() => _$TenantsToJson(this); } diff --git a/frontend/mgramseva/lib/widgets/custom_app_bar.dart b/frontend/mgramseva/lib/widgets/custom_app_bar.dart index 362919b54..cdbd0bf51 100644 --- a/frontend/mgramseva/lib/widgets/custom_app_bar.dart +++ b/frontend/mgramseva/lib/widgets/custom_app_bar.dart @@ -3,6 +3,7 @@ import 'package:mgramseva/model/mdms/tenants.dart'; import 'package:mgramseva/providers/common_provider.dart'; import 'package:mgramseva/providers/language.dart'; import 'package:mgramseva/providers/tenants_provider.dart'; +import 'package:mgramseva/utils/constants/i18_key_constants.dart'; import 'package:mgramseva/utils/localization/application_localizations.dart'; import 'package:mgramseva/utils/common_methods.dart'; import 'package:mgramseva/utils/global_variables.dart'; @@ -80,7 +81,7 @@ class _CustomAppBarState extends State { } } - showDialogBox(result) { + showDialogBox(List tenants) { var commonProvider = Provider.of( navigatorKey.currentContext!, listen: false); @@ -96,83 +97,115 @@ class _CustomAppBarState extends State { barrierDismissible: commonProvider.userDetails!.selectedtenant != null, context: context, builder: (BuildContext context) { - return Stack(children: [ - Container( - margin: EdgeInsets.only( - left: MediaQuery.of(context).size.width > 720 - ? MediaQuery.of(context).size.width - - MediaQuery.of(context).size.width / 3 - : 0, - top: 60), - width: MediaQuery.of(context).size.width > 720 - ? MediaQuery.of(context).size.width / 3 - : MediaQuery.of(context).size.width, - height: res.length * 50 < 300 ? - res.length * 50 : 300, - color: Colors.white, - child: ListView( - padding: EdgeInsets.zero, - shrinkWrap: true, - children: List.generate(result.length, (index) { - return GestureDetector( - onTap: () { - commonProvider.setTenant(result[index]); - Navigator.pop(context); - CommonMethods.home(); - }, - child: Material( - child: Container( - color: index.isEven - ? Colors.white - : Color.fromRGBO(238, 238, 238, 1), - width: MediaQuery.of(context).size.width, - height: 50, - padding: EdgeInsets.all(5), + var searchController = TextEditingController(); + var visibleTenants = tenants.asMap().values.toList(); + return StatefulBuilder( + builder: (context, StateSetter stateSetter) { + return Stack(children: [ + Container( + margin: EdgeInsets.only( + left: MediaQuery.of(context).size.width > 720 + ? MediaQuery.of(context).size.width - + MediaQuery.of(context).size.width / 3 + : 0, + top: 60), + width: MediaQuery.of(context).size.width > 720 + ? MediaQuery.of(context).size.width / 3 + : MediaQuery.of(context).size.width, + height: (visibleTenants.length * 50 < 300 ? + visibleTenants.length * 50 : 300)+ 60, + color: Colors.white, + child: ListView( + padding: EdgeInsets.zero, + shrinkWrap: true, + children: [ + Material( child: Padding( - padding: const EdgeInsets.all(10), - child: Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Text( - ApplicationLocalizations.of(context) - .translate(result[index].code!), - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w400, - color: commonProvider.userDetails! - .selectedtenant != - null && - commonProvider - .userDetails! - .selectedtenant! - .city! - .code == - result[index].city!.code! - ? Theme.of(context).primaryColor - : Colors.black), - ), - Text(result[index].city!.code!, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w400, - color: commonProvider.userDetails! - .selectedtenant != - null && - commonProvider - .userDetails! - .selectedtenant! - .city! - .code == - result[index].city!.code! - ? Theme.of(context).primaryColor - : Colors.black)) - ]), + padding: const EdgeInsets.all(8.0), + child: TextField( + controller: searchController, + decoration: InputDecoration( + hintText: "${ApplicationLocalizations.of(context) + .translate(i18.common.SEARCH)}" + ), + onChanged: (text) { + if(text.isEmpty){ + stateSetter(()=>{ + visibleTenants = tenants.asMap().values.toList() + }); + }else{ + var tresult = tenants.where((e) => "${ApplicationLocalizations.of(context) + .translate(e.code!)}-${e.city!.code!}".toLowerCase().trim().contains(text.toLowerCase().trim())).toList(); + stateSetter(()=>{ + visibleTenants = tresult + }); + } + }, + ), ), - ))); - }), - )) - ]); + ), + ...List.generate(visibleTenants.length, (index) { + return GestureDetector( + onTap: () { + commonProvider.setTenant(visibleTenants[index]); + Navigator.pop(context); + CommonMethods.home(); + }, + child: Material( + child: Container( + color: index.isEven + ? Colors.white + : Color.fromRGBO(238, 238, 238, 1), + width: MediaQuery.of(context).size.width, + height: 50, + padding: EdgeInsets.all(5), + child: Padding( + padding: const EdgeInsets.all(10), + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Text( + ApplicationLocalizations.of(context) + .translate(visibleTenants[index].code!), + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w400, + color: commonProvider.userDetails! + .selectedtenant != + null && + commonProvider + .userDetails! + .selectedtenant! + .city! + .code == + visibleTenants[index].city!.code! + ? Theme.of(context).primaryColor + : Colors.black), + ), + Text(visibleTenants[index].city!.code!, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w400, + color: commonProvider.userDetails! + .selectedtenant != + null && + commonProvider + .userDetails! + .selectedtenant! + .city! + .code == + visibleTenants[index].city!.code! + ? Theme.of(context).primaryColor + : Colors.black)) + ]), + ), + ))); + },growable: true)], + )) + ]); + } + ); }); }