From 633059b0be145d96b332726b4ba9b4dd1c0d4353 Mon Sep 17 00:00:00 2001 From: "taha.alam" Date: Wed, 2 Oct 2024 08:27:26 +0300 Subject: [PATCH] WD: Location dialog is added. --- lib/config/localized_values.dart | 2 + lib/pages/landing/widgets/services_view.dart | 10 +- lib/uitl/translations_delegate_base.dart | 2 + .../dialogs/location_selection_dialog.dart | 300 ++++++++++++++++++ 4 files changed, 307 insertions(+), 7 deletions(-) create mode 100644 lib/widgets/dialogs/location_selection_dialog.dart diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 95d7dd8f..7107d357 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -1978,4 +1978,6 @@ const Map localizedValues = { "myinstructions": {"en": "My Instructions", "ar": "تعليماتي"}, "clinicLocation": {"en": "Clinic Location", "ar": "موقع العيادة"}, "searchClinic": {"en": "Search Clinic", "ar": "بحث العيادة"}, + "selectBranch":{"en":"Select Branch", "ar":"اختر الفرع"}, + "searchByBranch":{"en":"Search By Branch Name", "ar":"البحث عن طريق اسم الفرع"} }; diff --git a/lib/pages/landing/widgets/services_view.dart b/lib/pages/landing/widgets/services_view.dart index 2527d3a0..79e93279 100644 --- a/lib/pages/landing/widgets/services_view.dart +++ b/lib/pages/landing/widgets/services_view.dart @@ -41,6 +41,7 @@ import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; import 'package:diplomaticquarterapp/uitl/utils_new.dart'; import 'package:diplomaticquarterapp/widgets/dialogs/covid_consent_dialog.dart'; +import 'package:diplomaticquarterapp/widgets/dialogs/location_selection_dialog.dart'; import 'package:diplomaticquarterapp/widgets/dialogs/radio_selection_dialog.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; @@ -191,16 +192,11 @@ class ServicesView extends StatelessWidget { Utils.navigationProjectsList.forEach((v) { projectsListLocal.add(new HospitalsModel.fromJson(v)); }); - List list = [ - for (int i = 0; i < projectsListLocal.length; i++) RadioSelectionDialogModel(projectsListLocal[i].name! + ' ${projectsListLocal[i].distanceInKilometers} ' + TranslationBase.of(context).km, i), - ]; showDialog( context: context, - builder: (cxt) => RadioSelectionDialog( - buttonText: TranslationBase.of(context).confirm, - listData: list, + builder: (cxt) => LocationSelectionDialog( + data: projectsListLocal, selectedIndex: _selectedHospitalIndex, - isScrollable: true, onValueSelected: (index) { _selectedHospitalIndex = index; initPenguinSDK(projectsListLocal[index].iD); diff --git a/lib/uitl/translations_delegate_base.dart b/lib/uitl/translations_delegate_base.dart index 59604293..01e737a8 100644 --- a/lib/uitl/translations_delegate_base.dart +++ b/lib/uitl/translations_delegate_base.dart @@ -2965,6 +2965,8 @@ class TranslationBase { String get myinstructions => localizedValues["myinstructions"][locale.languageCode]; String get clinicLocation => localizedValues["clinicLocation"][locale.languageCode]; String get searchClinic => localizedValues["searchClinic"][locale.languageCode]; + String get selectBranch => localizedValues["selectBranch"][locale.languageCode]; + String get searchByBranch => localizedValues["searchByBranch"][locale.languageCode]; } diff --git a/lib/widgets/dialogs/location_selection_dialog.dart b/lib/widgets/dialogs/location_selection_dialog.dart new file mode 100644 index 00000000..3fcfa7d5 --- /dev/null +++ b/lib/widgets/dialogs/location_selection_dialog.dart @@ -0,0 +1,300 @@ +import 'package:diplomaticquarterapp/core/model/hospitals/hospitals_model.dart'; +import 'package:diplomaticquarterapp/core/viewModels/medical/radiology_view_model.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; +import 'package:flutter/material.dart'; + +import '../../uitl/translations_delegate_base.dart'; + +class LocationSelectionDialog extends StatelessWidget { + final List data; + final Function(int)? onValueSelected; + final int? selectedIndex; + + const LocationSelectionDialog( + {super.key, + required this.data, + this.onValueSelected, + this.selectedIndex}); + + @override + Widget build(BuildContext context) { + return Dialog( + backgroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + ), + child: LocationDialogBody( + data: data, + onValueSelected: onValueSelected, + selectedIndex: selectedIndex, + )); + } +} + +class LocationDialogBody extends StatefulWidget { + final List data; + final Function(int)? onValueSelected; + final int? selectedIndex; + + const LocationDialogBody( + {super.key, + required this.data, + this.onValueSelected, + this.selectedIndex}); + + @override + State createState() => _LocationDialogBodyState(); +} + +class _LocationDialogBodyState extends State { + bool isListVisible = false; + int currentlySelected = -1; + + @override + Widget build(BuildContext context) { + return isListVisible + ? LocationListExpandedBody( + data: widget.data, + onItemClick: (data) { + if (data.isEmpty) return; + var selected = widget.data.indexWhere( + (item) => item.name == data, + ); + + if (selected == -1) return; + setState(() { + currentlySelected = selected; + isListVisible = false; + }); + }, + ) + : LocationListWrapBody( + onConfirmClicked: () { + widget.onValueSelected?.call(currentlySelected); + }, + onTextBoxClicked: () { + setState(() { + isListVisible = true; + }); + }, + selectedText: currentlySelected == -1 + ? "" + : widget.data[currentlySelected].name ?? ""); + } +} + +class LocationListExpandedBody extends StatefulWidget { + final List data; + final Function(String) onItemClick; + + const LocationListExpandedBody( + {super.key, required this.data, required this.onItemClick}); + + @override + State createState() => + _LocationListExpandedBodyState(); +} + +class _LocationListExpandedBodyState extends State { + List tempListData = []; + TextEditingController controller = new TextEditingController(); + + @override + void initState() { + super.initState(); + setState(() { + tempListData.addAll(widget.data); + }); + } + + @override + Widget build(BuildContext context) { + return Container( + child: Padding( + padding: const EdgeInsets.all(24), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + + Row( + children: [ + Expanded( + child: TextField( + controller: controller, + onChanged: (v) { + tempListData.clear(); + if (v.length > 0) { + for (int i = 0; i < widget.data.length; i++) { + if (widget.data[i].name + ?.toLowerCase() + .contains(v.toLowerCase()) == + true) { + tempListData.add(widget.data[i]); + } + } + } else { + tempListData.addAll(widget.data); + } + setState(() {}); + }, + decoration: InputDecoration( + hintStyle: TextStyle(fontSize: 12), + hintText: TranslationBase.of(context).searchByBranch, + suffixIcon: Icon(Icons.search), + contentPadding: EdgeInsets.symmetric(vertical: 9,horizontal: 14), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8.0), + borderSide: BorderSide( + color: Colors.grey, // Normal border color + width: 1.0, + ), + ), + ), + ), + ), + SizedBox(width: 8,), + InkWell( + onTap: () { + Navigator.of(context).pop(); + }, + child: Padding( + padding: const EdgeInsets.all(4.0), + child: Icon(Icons.close), + )) + ], + ), + SizedBox( + height: 16, + ), + + SizedBox( + height: 16, + ), + ListView.builder( + itemCount: tempListData.length, + shrinkWrap: true, + itemBuilder: (context, index) { + return Padding( + padding: EdgeInsets.only(bottom: 8), + child: SizedBox( + height: 24, + child: InkWell( + onTap: () { + widget + .onItemClick(tempListData[index].name ?? ""); + }, + child: Text( + "${tempListData[index].name ?? ""} ( ${tempListData[index].distanceInKilometers} km )", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + color: Colors.black, + letterSpacing: -0.96), + ), + ), + ), + ); + }) + ], + ), + ), + ); + } +} + +class LocationListWrapBody extends StatelessWidget { + final VoidCallback? onConfirmClicked; + final VoidCallback? onTextBoxClicked; + final String selectedText; + + const LocationListWrapBody( + {super.key, + this.onConfirmClicked, + this.onTextBoxClicked, + required this.selectedText}); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.all(24.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + TranslationBase.of(context).selectBranch, + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.w600, + color: Colors.black, + letterSpacing: -0.96), + ), + InkWell( + onTap: () { + Navigator.of(context).pop(); + }, + child: Padding( + padding: const EdgeInsets.all(4.0), + child: Icon(Icons.close), + )) + ], + ), + SizedBox( + height: 24, + ), + ListTile( + onTap: () { + onTextBoxClicked?.call(); + }, + title: Text( + TranslationBase.of(context).selectBranch, + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + color: Colors.black, + letterSpacing: -0.96), + ), + subtitle: selectedText.isEmpty + ? null + : Text( + selectedText, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w400, + color: Colors.black, + letterSpacing: -0.96), + ), + trailing: Icon( + Icons.arrow_drop_down_outlined, + color: Colors.black, + ), + shape: RoundedRectangleBorder( + side: BorderSide(color: Colors.grey, width: 1), + borderRadius: BorderRadius.circular(8), + ), + ), + SizedBox( + height: 24, + ), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Expanded( + child: DefaultButton( + TranslationBase.of(context).confirm, + () { + Navigator.pop(context); + onConfirmClicked?.call(); + }, + color: Colors.red, + ), + ), + ], + ), + ], + ), + ); + } +}