From 1282b5a415e09e4c8715ddbf98367dd2e280d464 Mon Sep 17 00:00:00 2001 From: Aamir Muhammad Date: Wed, 9 Jul 2025 12:09:34 +0300 Subject: [PATCH] consumer on welcome & language & font --- assets/images/svg/apple-finder.svg | 5 + assets/images/svg/language.svg | 6 + assets/images/svg/note-edit.svg | 6 + lib/core/viewModels/project_view_model.dart | 1 - lib/pages/login/welcome.dart | 644 ++++++++++++++------ lib/widgets/drawer/langauge_picker.dart | 67 ++ lib/widgets/others/app_scaffold_widget.dart | 75 ++- 7 files changed, 598 insertions(+), 206 deletions(-) create mode 100644 assets/images/svg/apple-finder.svg create mode 100644 assets/images/svg/language.svg create mode 100644 assets/images/svg/note-edit.svg create mode 100644 lib/widgets/drawer/langauge_picker.dart diff --git a/assets/images/svg/apple-finder.svg b/assets/images/svg/apple-finder.svg new file mode 100644 index 00000000..014083f9 --- /dev/null +++ b/assets/images/svg/apple-finder.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/assets/images/svg/language.svg b/assets/images/svg/language.svg new file mode 100644 index 00000000..0a976449 --- /dev/null +++ b/assets/images/svg/language.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/assets/images/svg/note-edit.svg b/assets/images/svg/note-edit.svg new file mode 100644 index 00000000..daed336b --- /dev/null +++ b/assets/images/svg/note-edit.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/lib/core/viewModels/project_view_model.dart b/lib/core/viewModels/project_view_model.dart index 68e2b5a6..065ed77d 100644 --- a/lib/core/viewModels/project_view_model.dart +++ b/lib/core/viewModels/project_view_model.dart @@ -155,7 +155,6 @@ class ProjectViewModel extends BaseViewModel { currentLanguage = 'en'; sharedPref.setString(APP_LANGUAGE, 'en'); } - notifyListeners(); } diff --git a/lib/pages/login/welcome.dart b/lib/pages/login/welcome.dart index 3ab54304..57be605c 100644 --- a/lib/pages/login/welcome.dart +++ b/lib/pages/login/welcome.dart @@ -24,12 +24,15 @@ import 'package:hmg_patient_app/pages/rateAppointment/rate_appointment_doctor.da import 'package:hmg_patient_app/services/authentication/auth_provider.dart'; import 'package:hmg_patient_app/services/clinic_services/get_clinic_service.dart'; import 'package:hmg_patient_app/theme/colors.dart'; +import 'package:hmg_patient_app/theme/theme_notifier.dart'; +import 'package:hmg_patient_app/theme/theme_value.dart'; import 'package:hmg_patient_app/uitl/app_shared_preferences.dart'; import 'package:hmg_patient_app/uitl/app_toast.dart'; import 'package:hmg_patient_app/uitl/gif_loader_dialog_utils.dart'; import 'package:hmg_patient_app/uitl/translations_delegate_base.dart'; import 'package:hmg_patient_app/uitl/utils.dart'; import 'package:hmg_patient_app/widgets/buttons/defaultButton.dart'; +import 'package:hmg_patient_app/widgets/drawer/langauge_picker.dart'; import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart'; import 'package:hmg_patient_app/widgets/otp/sms-popup.dart'; import 'package:hmg_patient_app/widgets/text/app_texts_widget.dart'; @@ -74,7 +77,6 @@ class _WelcomeLogin extends State { late ToDoCountProviderModel toDoProvider; - late int selectedOption; bool onlySMSBox = false; @@ -89,6 +91,8 @@ class _WelcomeLogin extends State { var dob; late int isHijri; var healthId; + int _selectedLanguage = 0; + @override void initState() { @@ -96,212 +100,459 @@ class _WelcomeLogin extends State { super.initState(); } - Widget build(BuildContext context) { + void changeLanguage(ProjectViewModel projectViewModel, int value) { + sharedPref.setBool(IS_ROBOT_INIT, false); + sharedPref.remove(CLINICS_LIST); + if (projectViewModel.isArabic) { + _selectedLanguage = value; + projectViewModel.changeLanguage('en'); + + locator().hamburgerMenu.logMenuItemClick('change language to english'); + } else { + _selectedLanguage = value; + projectViewModel.changeLanguage('ar'); + locator().hamburgerMenu.logMenuItemClick('change language to arabic'); + } + var themeNotifier = Provider.of(context, listen: false); + themeNotifier.setTheme(defaultTheme(fontName: projectViewModel.isArabic ? 'Cairo' : 'Poppins')); + } - projectViewModel = Provider.of(context); - toDoProvider = Provider.of(context); - - return AppScaffold( - appBarTitle: TranslationBase.of(context).welcome, - isShowDecPage: false, - isShowAppBar: true, - isshowBackButton: false, - showNewAppBar: true, - backgroundColor: Color(0xffF8F8F8), - showNewAppBarTitle: false, - body: Column( - children: [ - Expanded( - child: ListView( - padding: EdgeInsets.only(left: 21, right: 21), - physics: BouncingScrollPhysics(), - children: [ - SizedBox(height: 30), - Row( + @override + Widget build(BuildContext context) { + final initialProjectViewModel = Provider.of(context, listen: false); + // _selectedLanguage = initialProjectViewModel.isArabic ? 0 : 1; + + return Consumer2( + builder: (context, projectViewModel, toDoProvider, child) { + _selectedLanguage = projectViewModel.isArabic ? 0 : 1; + return AppScaffold( + appBarTitle: TranslationBase.of(context).welcome, + isShowDecPage: false, + isShowAppBar: true, + isshowBackButton: false, + showNewAppBar: true, + backgroundColor: Color(0xffF8F8F8), + showNewAppBarTitle: false, + showDropDown: true, + isShowLanguageChanger: true, + appBarIcons: [], + dropDownList: [ + TranslationBase.of(context).arabicChange, + TranslationBase.of(context).english, + ], + dropDownIndexChange: (value) { + changeLanguage(projectViewModel, value!); + }, + dropdownIndexValue: _selectedLanguage, + // Use the state variable + body: Column( + children: [ + Expanded( + child: ListView( + padding: EdgeInsets.only(left: 21, right: 21), + physics: BouncingScrollPhysics(), children: [ - SvgPicture.asset( - "assets/images/new/hmg_icon.svg", - height: 62, - width: 62, + SizedBox(height: 30), + Row( + children: [ + SvgPicture.asset( + "assets/images/new/hmg_icon.svg", + height: 62, + width: 62, + ), + ], ), + // Example of using toDoProvider: + // if (toDoProvider.count > 0) Text("To-Do items: ${toDoProvider.count}"), ], ), - ], - ), - ), - Spacer(), - Expanded( - child: Container( - padding: EdgeInsets.only(top: 30, bottom: 0, right: 21, left: 21), - child: Text( - // TranslationBase.of(context).welcome, - "Welcome to Dr. Sulaiman Al Habib Medical Group", - style: TextStyle(fontSize: 36, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.4, height: 47 / 36), ), - ), - ), - Container( - padding: EdgeInsets.only(top: 16, bottom: 10, right: 21, left: 21), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Directionality( - textDirection: TextDirection.ltr, - child: inputWidget( - "National ID. or File No", - "1xxxxxxxx", - nationIdController, - isEnable: true, - prefix: null, - hasSelection: false, - isBorderAllowed: false, - isAllowLeadingIcon: true, - leadingIcon: "assets/images/svg/student-card.svg", - ), - ), - ], - ), - ), - SizedBox( - height: 15, - ), - Row( - mainAxisSize: MainAxisSize.min, - children: [ + Spacer(), Expanded( child: Container( - padding: EdgeInsets.only(top: 0, bottom: 16, right: 21, left: 21), - child: DefaultButton( - TranslationBase.of(context).login, - () { - bool isValid = validateIqama(nationIdController.text); - print("Iqama is valid: $isValid"); - - if (isValid) { - showModalBottomSheet( - context: context, - isScrollControlled: true, - isDismissible: false, - backgroundColor: Colors.transparent, - builder: (context) => Padding( - padding: EdgeInsets.only( - bottom: MediaQuery.of(context).viewInsets.bottom, - ), - child: SingleChildScrollView( - child: GenericBottomSheet( - countryCode: "966", // Default is +966 as in your example - initialPhoneNumber: "", // - textController: phoneController, - buttons: [ - Padding( - padding: const EdgeInsets.only(bottom: 10), - child: CustomButton( - text: "Send me OTP on SMS", - onPressed: () { - onOtpBtnPressed(OTPType.sms); - }, - backgroundColor: Colors.red, - borderColor: Colors.red, - textColor: Colors.white, - icon: "assets/images/svg/message.svg", - ), - ), - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ + padding: EdgeInsets.only(top: 30, bottom: 0, right: 21, left: 21), + child: Text( + "Welcome to Dr. Sulaiman Al Habib Medical Group", + style: TextStyle(fontSize: 36, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.4, height: 47 / 36), + ), + ), + ), + Container( + padding: EdgeInsets.only(top: 16, bottom: 10, right: 21, left: 21), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Directionality( + textDirection: TextDirection.ltr, // Consider making this dynamic based on language + child: inputWidget( + "National ID. or File No", + "1xxxxxxxx", + nationIdController, // Assumed to be a TextEditingController in your State class + isEnable: true, + prefix: null, + hasSelection: false, + isBorderAllowed: false, + isAllowLeadingIcon: true, + leadingIcon: "assets/images/svg/student-card.svg", + ), + ), + ], + ), + ), + SizedBox( + height: 15, + ), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Expanded( + child: Container( + padding: EdgeInsets.only(top: 0, bottom: 16, right: 21, left: 21), + child: DefaultButton( + TranslationBase.of(context).login, + () { + bool isValid = validateIqama(nationIdController.text); + print("Iqama is valid: $isValid"); + + if (isValid) { + showModalBottomSheet( + context: context, + isScrollControlled: true, + isDismissible: false, + backgroundColor: Colors.transparent, + builder: (bottomSheetContext) => Padding( + // Use a different context name + padding: EdgeInsets.only( + bottom: MediaQuery.of(bottomSheetContext).viewInsets.bottom, + ), + child: SingleChildScrollView( + child: GenericBottomSheet( + countryCode: "966", + initialPhoneNumber: "", + textController: phoneController, // Assumed to be a TextEditingController + buttons: [ + Padding( + padding: const EdgeInsets.only(bottom: 10), + child: CustomButton( + text: "Send me OTP on SMS", + onPressed: () { + onOtpBtnPressed(OTPType.sms); + }, + backgroundColor: Colors.red, + borderColor: Colors.red, + textColor: Colors.white, + icon: "assets/images/svg/message.svg", + ), + ), + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: AppText( + "OR", + fontSize: 16, + fontFamily: 'poppins', + color: Color(0xFF2E3039), + fontWeight: FontWeight.w500, + ), + ), + ], + ), Padding( - padding: const EdgeInsets.symmetric(horizontal: 8), - child: AppText( - "OR", - fontSize: 16, - fontFamily: 'poppins', - color: Color(0xFF2E3039), - fontWeight: FontWeight.w500, + padding: const EdgeInsets.only(bottom: 10), + child: CustomButton( + text: "Send me OTP on WhatsApp", + onPressed: () { + onOtpBtnPressed(OTPType.whatsapp); + }, + backgroundColor: Colors.white, + borderColor: Color(0xFF2E3039), + textColor: Color(0xFF2E3039), + icon: "assets/images/svg/whatsapp.svg", ), ), ], ), - Padding( - padding: const EdgeInsets.only(bottom: 10), - child: CustomButton( - text: "Send me OTP on WhatsApp", - onPressed: () { - onOtpBtnPressed(OTPType.whatsapp); - }, - backgroundColor: Colors.white, - borderColor: Color(0xFF2E3039), - textColor: Color(0xFF2E3039), - icon: "assets/images/svg/whatsapp.svg", - ), - ), - ], - ), - ), - )); - } else { - Utils.showErrorToast("Please enter a valid Iqama number."); - } - }, - // color: CustomColors., - textColor: Colors.white, + ), + )); + } else { + Utils.showErrorToast("Please enter a valid Iqama number."); + } + }, + textColor: Colors.white, + ), + ), ), - ), + ], ), - // SizedBox(width: 8), - // Expanded( - // child: DefaultButton( - // TranslationBase.of(context).yes, - // () => { - // Navigator.of(context).push(FadePage(page: LoginType())), - // locator().loginRegistration.visited_alhabib_group(true), - // }, - // color: CustomColors.green, - // ), - // ), - ], - ), - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - RichText( - textAlign: TextAlign.center, - text: TextSpan( - style: TextStyle( - color: Colors.black, - fontSize: 16, - height: 26 / 16, - fontFamily: 'poppins', - fontWeight: FontWeight.w500, - ), - children: [ - TextSpan(text: 'Don’t have an account? '), - TextSpan( - text: 'Register now', - style: const TextStyle( - color: Colors.red, + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + RichText( + textAlign: TextAlign.center, + text: TextSpan( + style: TextStyle( + color: Colors.black, fontSize: 16, height: 26 / 16, fontFamily: 'poppins', fontWeight: FontWeight.w500, ), - recognizer: TapGestureRecognizer() - ..onTap = () { - Navigator.of(context).push(FadePage(page: RegisterNew())); - // Example: Navigator.push(context, MaterialPageRoute(builder: (context) => RegisterScreen())); - }, + children: [ + TextSpan(text: 'Don’t have an account? '), + TextSpan( + text: 'Register now', + style: const TextStyle( + color: Colors.red, + fontSize: 16, + height: 26 / 16, + fontFamily: 'poppins', + fontWeight: FontWeight.w500, + ), + recognizer: TapGestureRecognizer() + ..onTap = () { + Navigator.of(context).push(FadePage(page: RegisterNew())); + locator().loginRegistration.visited_alhabib_group(true); + }, + ), + ], ), - ], - ), - ), + ), + ], + ) ], - ) - ], - ), + ), + ); + }, ); } + // Widget build(BuildContext context) { + // projectViewModel = Provider.of(context); + // projectViewModel.isArabic ? _selectedLanguage = 0 : 1; + // toDoProvider = Provider.of(context); + // return AppScaffold( + // appBarTitle: TranslationBase.of(context).welcome, + // isShowDecPage: false, + // isShowAppBar: true, + // isshowBackButton: false, + // showNewAppBar: true, + // backgroundColor: Color(0xffF8F8F8), + // showNewAppBarTitle: false, + // showDropDown: true, + // isShowLanguageChanger: true, + // appBarIcons: [], + // dropDownList: [ + // TranslationBase.of(context).arabicChange, + // TranslationBase.of(context).english, + // ], + // dropDownIndexChange: (value) { + // _selectedLanguage = value!; + // if (projectViewModel.isArabic) { + // projectViewModel.changeLanguage('en'); + // locator().hamburgerMenu.logMenuItemClick('change language to english'); + // } else { + // projectViewModel.changeLanguage('ar'); + // locator().hamburgerMenu.logMenuItemClick('change language to arabic'); + // } + // }, + // dropdownIndexValue: _selectedLanguage, + // body: Column( + // children: [ + // Expanded( + // child: ListView( + // padding: EdgeInsets.only(left: 21, right: 21), + // physics: BouncingScrollPhysics(), + // children: [ + // SizedBox(height: 30), + // Row( + // children: [ + // SvgPicture.asset( + // "assets/images/new/hmg_icon.svg", + // height: 62, + // width: 62, + // ), + // ], + // ), + // ], + // ), + // ), + // Spacer(), + // Expanded( + // child: Container( + // padding: EdgeInsets.only(top: 30, bottom: 0, right: 21, left: 21), + // child: Text( + // // TranslationBase.of(context).welcome, + // "Welcome to Dr. Sulaiman Al Habib Medical Group", + // style: TextStyle(fontSize: 36, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.4, height: 47 / 36), + // ), + // ), + // ), + // Container( + // padding: EdgeInsets.only(top: 16, bottom: 10, right: 21, left: 21), + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.stretch, + // children: [ + // Directionality( + // textDirection: TextDirection.ltr, + // child: inputWidget( + // "National ID. or File No", + // "1xxxxxxxx", + // nationIdController, + // isEnable: true, + // prefix: null, + // hasSelection: false, + // isBorderAllowed: false, + // isAllowLeadingIcon: true, + // leadingIcon: "assets/images/svg/student-card.svg", + // ), + // ), + // ], + // ), + // ), + // SizedBox( + // height: 15, + // ), + // Row( + // mainAxisSize: MainAxisSize.min, + // children: [ + // Expanded( + // child: Container( + // padding: EdgeInsets.only(top: 0, bottom: 16, right: 21, left: 21), + // child: DefaultButton( + // TranslationBase.of(context).login, + // () { + // bool isValid = validateIqama(nationIdController.text); + // print("Iqama is valid: $isValid"); + // + // if (isValid) { + // showModalBottomSheet( + // context: context, + // isScrollControlled: true, + // isDismissible: false, + // backgroundColor: Colors.transparent, + // builder: (context) => Padding( + // padding: EdgeInsets.only( + // bottom: MediaQuery.of(context).viewInsets.bottom, + // ), + // child: SingleChildScrollView( + // child: GenericBottomSheet( + // countryCode: "966", // Default is +966 as in your example + // initialPhoneNumber: "", // + // textController: phoneController, + // buttons: [ + // Padding( + // padding: const EdgeInsets.only(bottom: 10), + // child: CustomButton( + // text: "Send me OTP on SMS", + // onPressed: () { + // onOtpBtnPressed(OTPType.sms); + // }, + // backgroundColor: Colors.red, + // borderColor: Colors.red, + // textColor: Colors.white, + // icon: "assets/images/svg/message.svg", + // ), + // ), + // Row( + // crossAxisAlignment: CrossAxisAlignment.center, + // mainAxisAlignment: MainAxisAlignment.center, + // children: [ + // Padding( + // padding: const EdgeInsets.symmetric(horizontal: 8), + // child: AppText( + // "OR", + // fontSize: 16, + // fontFamily: 'poppins', + // color: Color(0xFF2E3039), + // fontWeight: FontWeight.w500, + // ), + // ), + // ], + // ), + // Padding( + // padding: const EdgeInsets.only(bottom: 10), + // child: CustomButton( + // text: "Send me OTP on WhatsApp", + // onPressed: () { + // onOtpBtnPressed(OTPType.whatsapp); + // }, + // backgroundColor: Colors.white, + // borderColor: Color(0xFF2E3039), + // textColor: Color(0xFF2E3039), + // icon: "assets/images/svg/whatsapp.svg", + // ), + // ), + // ], + // ), + // ), + // )); + // } else { + // Utils.showErrorToast("Please enter a valid Iqama number."); + // } + // }, + // // color: CustomColors., + // textColor: Colors.white, + // ), + // ), + // ), + // // SizedBox(width: 8), + // // Expanded( + // // child: DefaultButton( + // // TranslationBase.of(context).yes, + // // () => { + // // Navigator.of(context).push(FadePage(page: LoginType())), + // // locator().loginRegistration.visited_alhabib_group(true), + // // }, + // // color: CustomColors.green, + // // ), + // // ), + // ], + // ), + // Row( + // crossAxisAlignment: CrossAxisAlignment.center, + // mainAxisAlignment: MainAxisAlignment.center, + // children: [ + // RichText( + // textAlign: TextAlign.center, + // text: TextSpan( + // style: TextStyle( + // color: Colors.black, + // fontSize: 16, + // height: 26 / 16, + // fontFamily: 'poppins', + // fontWeight: FontWeight.w500, + // ), + // children: [ + // TextSpan(text: 'Don’t have an account? '), + // TextSpan( + // text: 'Register now', + // style: const TextStyle( + // color: Colors.red, + // fontSize: 16, + // height: 26 / 16, + // fontFamily: 'poppins', + // fontWeight: FontWeight.w500, + // ), + // recognizer: TapGestureRecognizer() + // ..onTap = () { + // Navigator.of(context).push(FadePage(page: RegisterNew())); + // // Example: Navigator.push(context, MaterialPageRoute(builder: (context) => RegisterScreen())); + // }, + // ), + // ], + // ), + // ), + // ], + // ) + // ], + // ), + // ); + // } + void onOtpBtnPressed(OTPType type) { if (phoneController.text.isEmpty) { Utils.showErrorToast("Please enter your phone number."); @@ -488,14 +739,14 @@ class _WelcomeLogin extends State { userData = result.list, sharedPref.setString(BLOOD_TYPE, result.patientBloodType ?? ""), //Remove o+ from here Added by Aamir - authenticatedUserObject.user = result.list, - projectViewModel.setPrivilege(privilegeList: res), + authenticatedUserObject.user = result.list, + projectViewModel.setPrivilege(privilegeList: res), await sharedPref.setObject(MAIN_USER, result.list), await sharedPref.setObject(USER_PROFILE, result.list), loginTokenID = result.logInTokenID, await sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), await sharedPref.setString(TOKEN, result.authenticationTokenID), - checkIfUserAgreedBefore(result), + checkIfUserAgreedBefore(result), // projectViewModel.analytics.loginRegistration.login_successful(), } } @@ -644,7 +895,7 @@ class _WelcomeLogin extends State { isArabic: projectViewModel.isArabic, ), ), - (r) => false); + (r) => false); }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); print(err); @@ -669,22 +920,20 @@ class _WelcomeLogin extends State { getToDoCount(); checkIfIsInPatient(); - appointmentRateViewModel - .getIsLastAppointmentRatedList(projectViewModel.isArabic ? 1 : 2) - .then((_) { + appointmentRateViewModel.getIsLastAppointmentRatedList(projectViewModel.isArabic ? 1 : 2).then((_) { GifLoaderDialogUtils.hideDialog(AppGlobal.context); if (appointmentRateViewModel.isHaveAppointmentNotRate) { Navigator.pushAndRemoveUntil( context, FadePage(page: RateAppointmentDoctor()), - (route) => false, + (route) => false, ); } else { Navigator.pushAndRemoveUntil( context, FadePage(page: LandingPage()), - (route) => false, + (route) => false, ); } insertIMEI(); @@ -695,9 +944,7 @@ class _WelcomeLogin extends State { void getToDoCount() { toDoProvider.setState(0, 0, true, "0"); - ClinicListService() - .getActiveAppointmentNo(context) - .then((res) { + ClinicListService().getActiveAppointmentNo(context).then((res) { if (res['MessageStatus'] == 1) { toDoProvider.setState( res['AppointmentActiveNumber'], @@ -741,11 +988,4 @@ class _WelcomeLogin extends State { } }); } - - } - - - - - - +} diff --git a/lib/widgets/drawer/langauge_picker.dart b/lib/widgets/drawer/langauge_picker.dart new file mode 100644 index 00000000..0d7bb380 --- /dev/null +++ b/lib/widgets/drawer/langauge_picker.dart @@ -0,0 +1,67 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/flutter_svg.dart'; + +class LanguageSelector extends StatefulWidget { + final String currentLanguage; + final ValueChanged onLanguageChanged; + final List> languages; + + const LanguageSelector({ + super.key, + required this.currentLanguage, + required this.onLanguageChanged, + required this.languages, + }); + + @override + State createState() => _LanguageSelectorState(); +} + +class _LanguageSelectorState extends State { + @override + Widget build(BuildContext context) { + final currentLangData = widget.languages.firstWhere( + (lang) => lang['code'] == widget.currentLanguage, + orElse: () => {'code': 'en', 'name': 'English'}, + ); + + return Stack(clipBehavior: Clip.none, children: [ + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + color: Color(0xFFFEE9EA), + ), + height: 40, + width: 93, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + InkWell( + onTap: () { + final newLanguage = widget.currentLanguage == 'ar' ? 'en' : 'ar'; + widget.onLanguageChanged(newLanguage); + }, + child: Container( + padding: EdgeInsets.all(8), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + SvgPicture.asset("assets/images/svg/language.svg", width: 24), + const SizedBox(width: 8), + Text( + currentLangData['name']?.toUpperCase() ?? 'EN', + style: const TextStyle(fontWeight: FontWeight.w500, fontFamily: 'GESSTwo', fontSize: 14, color: Color(0xFFED1C2B)), + ), + ], + ), + ), + ), + ], + ), + ), + ]); + } +} diff --git a/lib/widgets/others/app_scaffold_widget.dart b/lib/widgets/others/app_scaffold_widget.dart index 36ebc210..b611c761 100644 --- a/lib/widgets/others/app_scaffold_widget.dart +++ b/lib/widgets/others/app_scaffold_widget.dart @@ -25,6 +25,7 @@ import 'package:hmg_patient_app/uitl/translations_delegate_base.dart'; import 'package:hmg_patient_app/uitl/utils.dart'; import 'package:hmg_patient_app/uitl/utils_new.dart'; import 'package:hmg_patient_app/widgets/data_display/text.dart'; +import 'package:hmg_patient_app/widgets/drawer/langauge_picker.dart'; import 'package:hmg_patient_app/widgets/pharmacy/bottom_nav_pharmacy_bar.dart'; import 'package:hmg_patient_app/widgets/progress_indicator/app_loader_widget.dart'; import 'package:hmg_patient_app/widgets/transitions/fade_page.dart'; @@ -84,6 +85,7 @@ class AppScaffold extends StatefulWidget { final bool isShowPharmacyAppbar; final bool isshowBackButton; final Widget? customAppBar; + final bool isShowLanguageChanger; AppScaffold setOnAppBarCartClick(VoidCallback onClick) { _onCartClick = onClick; @@ -132,7 +134,8 @@ class AppScaffold extends StatefulWidget { this.backButtonTab, this.changeCurrentTab, this.currentTab, - this.isShowPharmacyAppbar = false}); + this.isShowPharmacyAppbar = false, + this.isShowLanguageChanger = false}); @override _AppScaffoldState createState() => _AppScaffoldState(); @@ -245,6 +248,7 @@ class _AppScaffoldState extends State { isShowBackButton: widget.isshowBackButton, dropDownIndexChange: widget.dropDownIndexChange, appBarIcons: widget.appBarIcons, + isShowLanguageChanger: widget.isShowLanguageChanger, onTap: () { widget.onTap; }, @@ -348,6 +352,7 @@ class NewAppBarWidget extends StatelessWidget implements PreferredSizeWidget { List? dropDownList; final void Function(int?)? dropDownIndexChange; final List? appBarIcons; + final bool isShowLanguageChanger; VoidCallback? onTap; @@ -361,7 +366,8 @@ class NewAppBarWidget extends StatelessWidget implements PreferredSizeWidget { this.dropdownIndexValue, this.dropDownIndexChange, this.onTap, - this.isShowBackButton = true}) + this.isShowBackButton = true, + this.isShowLanguageChanger = false}) : super(key: key); @override @@ -391,7 +397,7 @@ class NewAppBarWidget extends StatelessWidget implements PreferredSizeWidget { fontSize: 24, fontFamily: (projectViewModel.isArabic ? 'Cairo' : 'Poppins'), fontWeight: FontWeight.w700, color: Color(0xff2B353E), letterSpacing: -1.44, height: 35 / 24), ), ), - if (showDropDown!) + if (showDropDown! && !isShowLanguageChanger) Container( decoration: containerRadius(Color(0xFFF7F7F7), 30), height: 30, @@ -428,6 +434,69 @@ class NewAppBarWidget extends StatelessWidget implements PreferredSizeWidget { ), ), ), + if (showDropDown! && isShowLanguageChanger) + Padding( + padding: EdgeInsets.symmetric(horizontal: 20), + child: Directionality( + textDirection: TextDirection.ltr, + child: LanguageSelector( + currentLanguage: dropdownIndexValue == 0 ? 'ar' : 'en', + onLanguageChanged: (String value) { + print(value); + print(value); + dropDownIndexChange!(value == 'ar' ? 0 : 1); + // dropdownIndexValue = value == 'ar' ? 0 : 1; + + }, + languages: [ + {'code': 'ar', 'name': '${TranslationBase.of(context).arabicChange}'}, + {'code': 'en', 'name': '${TranslationBase.of(context).english}'} + ], + ), + ), + // child: Directionality( + // // Directionality( + // textDirection: TextDirection.ltr, + // child: Container( + // decoration: containerRadius(Color(0xFFFEE9EA), 12), + // height: 40, + // width: 93, + // // padding: EdgeInsets.all(10), + // child: DropdownButtonHideUnderline( + // child: ButtonTheme( + // alignedDropdown: true, + // child: DropdownButton( + // iconEnabledColor: CustomColors.darkOrange, + // style: TextStyle(color: CustomColors.black, fontSize: 12), + // dropdownColor: CustomColors.lightGreyColor, + // value: dropdownIndexValue, + // items: [ + // for (int i = 0; i < dropDownList!.length; i++) + // DropdownMenuItem( + // value: i, + // child: AutoSizeText( + // dropDownList![i], + // style: TextStyle( + // fontSize: 12, + // fontFamily: (projectViewModel.isArabic ? 'Cairo' : 'Poppins'), + // fontWeight: FontWeight.w600, + // color: Color(0xff2B2E31), + // letterSpacing: -.48, + // // height: 12 / 18 + // ), + // ), + // ) + // ], + // onChanged: dropDownIndexChange, + // underline: Container( + // height: 0, + // ), + // ), + // ), + // ), + // ), + // ), + ), ], ), actions: [