Change language dialog
unknown
dart
a year ago
11 kB
2
Indexable
Never
import 'dart:developer'; import 'package:base_architecture/core/constants/theme.dart'; import 'package:base_architecture/core/extensions/widget_extensions.dart'; import 'package:base_architecture/core/shared_widgets/ACScaffold.dart'; import 'package:base_architecture/core/shared_widgets/block_button_widget.dart'; import 'package:base_architecture/core/shared_widgets/custom_radio_button.dart'; import 'package:base_architecture/data_layer/models/radio_model.dart'; import 'package:base_architecture/presentation/notifiers/auth_notifier/auth_notifier.dart'; import 'package:base_architecture/presentation/notifiers/locale_notifier/locale_notifier.dart'; import 'package:base_architecture/presentation/notifiers/theme_notifier.dart'; import 'package:base_architecture/presentation/pages/main/main_page.dart'; import 'package:base_architecture/presentation/resources/color_manager.dart'; import 'package:base_architecture/presentation/setting_notifier.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_uxcam/flutter_uxcam.dart'; import 'package:provider/provider.dart'; import 'package:universal_file/universal_file.dart'; class ChangeLanguageDialog extends StatelessWidget { const ChangeLanguageDialog({Key? key}) : super(key: key); @override Widget build(BuildContext context) { Size mediaQuery = MediaQuery.of(context).size; ThemeNotifier themeNotifier = Provider.of<ThemeNotifier>( context, listen: true, ); LocaleNotifier localeNotifier = Provider.of<LocaleNotifier>( context, listen: true, ); AuthNotifier authNotifier = Provider.of<AuthNotifier>( context, listen: false, ); SettingsNotifier settingsNotifier = Provider.of<SettingsNotifier>( context, listen: false, ); return ACScaffold( backgroundColor: Colors.transparent, body: Align( alignment: Alignment.center, child: Container( margin: const EdgeInsets.only(bottom: 50, top: 300), width: mediaQuery.width * 0.85, decoration: BoxDecoration( color: themeNotifier.getTheme().primaryColor, borderRadius: const BorderRadius.all( Radius.circular(10), ), ), child: Padding( padding: EdgeInsets.symmetric( horizontal: mediaQuery.width * 0.04, vertical: mediaQuery.height * 0.024, ), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[ _closeDialogButton( themeNotifier, authNotifier, localeNotifier, context, mediaQuery, ), _dialogTitle(themeNotifier, mediaQuery), _allLanguagesRadios(authNotifier, themeNotifier), _confirmCancelButtons( localeNotifier, authNotifier, themeNotifier, mediaQuery, settingsNotifier, ) ], ), ), ), ), ); } Widget _confirmCancelButtons( LocaleNotifier localeNotifier, AuthNotifier authNotifier, ThemeNotifier themeNotifier, Size mediaQuery, SettingsNotifier settingsNotifier, ) => Padding( padding: EdgeInsets.symmetric( vertical: mediaQuery.height * 0.015, ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[ _confirmButton( localeNotifier, authNotifier, themeNotifier, settingsNotifier), const Spacer( flex: 1, ), _cancelButton(localeNotifier, authNotifier, themeNotifier), ], ), ); Widget _cancelButton( LocaleNotifier localeNotifier, AuthNotifier authNotifier, ThemeNotifier themeNotifier, ) => Expanded( flex: 8, child: BlockButtonWidget( buttonHeight: 55, text: Text( 'Cancel'.tr(), style: themeNotifier.getTheme().textTheme.headline2!.copyWith( fontSize: 20, fontWeight: FontWeight.bold, color: themeNotifier.getTheme().canvasColor, ), ), color: Colors.transparent, borderColor: themeNotifier.getTheme().canvasColor, borderWidth: 1.3, onPressed: () { localeNotifier.cancelAllSelectedLanguage(); Navigator.pop(navigatorKey.currentContext!); mixpanel?.track('Pressed back '); FlutterUxcam.logEvent('Pressed back '); }, ), ); Widget _confirmButton( LocaleNotifier localeNotifier, AuthNotifier authNotifer, ThemeNotifier themeNotifier, SettingsNotifier settingsNotifier, ) => Expanded( flex: 8, child: BlockButtonWidget( buttonHeight: 55, text: Text( 'Save'.tr(), style: themeNotifier.getTheme().textTheme.headline2!.copyWith( fontSize: 20, fontWeight: FontWeight.bold, color: ColorManager.white, ), ), color: HexColor.fromHex('#003260'), onPressed: () { localeNotifier.saveAllLanguage(); if (authNotifer.appUser != null) { settingsNotifier.changeAppLang(); } log(navigatorKey.currentContext!.locale.toString()); Navigator.pop(navigatorKey.currentContext!); mixpanel?.track('Pressed back '); FlutterUxcam.logEvent('Pressed back '); }), ); Widget _allLanguagesRadios( AuthNotifier authNotifier, ThemeNotifier themeNotifier, ) => Consumer<LocaleNotifier>( builder: (BuildContext context, LocaleNotifier notifier, Widget? child) => ListView( shrinkWrap: true, children: [ Column( children: <Widget>[ Semantics( button: true, child: InkWell( onTap: () { notifier.setToArabic(); }, child: CustomRadioButton( key, RadioModel( isSelected: notifier.isArabic, text: 'العربية', value: 'ar', ), ), ), ), Divider( color: HexColor.fromHex('#E9EBEF'), thickness: 1, indent: 25, endIndent: 20, height: 8, ), Semantics( button: true, child: InkWell( onTap: () { notifier.setToEnglish(); }, child: CustomRadioButton( key, RadioModel( isSelected: notifier.isEnglish, text: 'English', value: 'en', ), ), ), ), Visibility( visible: authNotifier.arabSettings?.tokenData?.isHebrew ?? false, child: Divider( color: HexColor.fromHex('#E9EBEF'), thickness: 1, indent: 25, endIndent: 20, height: 8, ), ), Visibility( visible: authNotifier.arabSettings?.tokenData?.isHebrew ?? false, child: Semantics( button: true, child: InkWell( onTap: () { notifier.setToHebrew(); }, child: CustomRadioButton( key, RadioModel( isSelected: notifier.isHebrew, text: 'Hebrew', value: 'he', ), ), ), ), ), ], ), ], ), ); Widget _dialogTitle( ThemeNotifier themeNotifier, Size mediaQuery, ) => Text( 'Change the language'.tr(), style: themeNotifier.getTheme().textTheme.headline5!.copyWith( color: themeNotifier.getTheme().hoverColor, fontSize: 25, fontWeight: FontWeight.bold, ), ).padding( padding: EdgeInsetsDirectional.only( start: 7, top: mediaQuery.height * 0.035, bottom: mediaQuery.height * 0.015, ), ); Widget _closeDialogButton( ThemeNotifier themeNotifier, AuthNotifier authNotifier, LocaleNotifier localeNotifier, BuildContext context, Size mediaQuery, ) => Align( alignment: AlignmentDirectional.topStart, child: Semantics( label: 'Close'.tr(), button: true, excludeSemantics: true, child: Container( height: 44, width: 44, decoration: BoxDecoration( color: themeNotifier.getTheme().focusColor, border: Border.all( color: themeNotifier.getTheme() == AppThemes().darkTheme ? Colors.transparent : HexColor.fromHex('#E9EBEF'), width: 1.5, ), borderRadius: const BorderRadius.all( Radius.circular(10), ), ), child: IconButton( iconSize: mediaQuery.height * 0.023, icon: Icon( Icons.close, color: themeNotifier.getTheme().hoverColor, ), onPressed: () { localeNotifier.cancelAllSelectedLanguage(); Navigator.of(context).pop(); mixpanel?.track('Pressed back '); FlutterUxcam.logEvent('Pressed back '); }, ), ), ), ); }