|
| 1 | +import 'package:expansion_tile_card/expansion_tile_card.dart'; |
| 2 | +import 'package:flood_mobile/Blocs/language_bloc/language_bloc.dart'; |
| 3 | +import 'package:flood_mobile/Blocs/theme_bloc/theme_bloc.dart'; |
| 4 | +import 'package:flood_mobile/Constants/languages.dart'; |
| 5 | +import 'package:flood_mobile/Pages/widgets/flood_snackbar.dart'; |
| 6 | +import 'package:flood_mobile/Pages/widgets/text_size.dart'; |
| 7 | +import 'package:flood_mobile/l10n/l10n.dart'; |
| 8 | +import 'package:flutter/material.dart'; |
| 9 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
| 10 | + |
| 11 | +class UserInterfaceSection extends StatelessWidget { |
| 12 | + final int themeIndex; |
| 13 | + final double hp; |
| 14 | + UserInterfaceSection({ |
| 15 | + Key? key, |
| 16 | + required this.themeIndex, |
| 17 | + required this.hp, |
| 18 | + }) : super(key: key); |
| 19 | + |
| 20 | + @override |
| 21 | + Widget build(BuildContext context) { |
| 22 | + final AppLocalizations l10n = context.l10n; |
| 23 | + return BlocBuilder<LanguageBloc, LanguageState>(builder: (context, state) { |
| 24 | + String selectedLanguageCode = state.locale?.languageCode ?? 'auto'; |
| 25 | + String selectedLanguage = Languages[selectedLanguageCode] ?? 'Automatic'; |
| 26 | + return ExpansionTileCard( |
| 27 | + key: Key('User Interface Expansion Card'), |
| 28 | + onExpansionChanged: (value) {}, |
| 29 | + elevation: 0, |
| 30 | + expandedColor: ThemeBloc.theme(themeIndex).primaryColor, |
| 31 | + baseColor: ThemeBloc.theme(themeIndex).primaryColor, |
| 32 | + expandedTextColor: ThemeBloc.theme(themeIndex).colorScheme.secondary, |
| 33 | + title: MText(text: l10n.settings_tabs_user_interface), |
| 34 | + leading: Icon(Icons.mobile_friendly), |
| 35 | + contentPadding: EdgeInsets.all(0), |
| 36 | + children: [ |
| 37 | + Column( |
| 38 | + key: Key('User Interface options display column'), |
| 39 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 40 | + mainAxisAlignment: MainAxisAlignment.start, |
| 41 | + children: [ |
| 42 | + Container( |
| 43 | + width: double.infinity, |
| 44 | + ), |
| 45 | + SText( |
| 46 | + text: l10n.settings_language_section_heading, |
| 47 | + themeIndex: themeIndex), |
| 48 | + SizedBox(height: 15), |
| 49 | + Column( |
| 50 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 51 | + children: [ |
| 52 | + Container( |
| 53 | + padding: EdgeInsets.symmetric(horizontal: 20), |
| 54 | + width: double.infinity, |
| 55 | + height: 60, |
| 56 | + decoration: BoxDecoration( |
| 57 | + color: ThemeBloc.theme(themeIndex).primaryColorLight, |
| 58 | + border: null, |
| 59 | + borderRadius: BorderRadius.circular(8), |
| 60 | + ), |
| 61 | + child: Center( |
| 62 | + child: DropdownButtonFormField<String>( |
| 63 | + key: Key('Select Language Dropdown'), |
| 64 | + dropdownColor: |
| 65 | + ThemeBloc.theme(themeIndex).primaryColorLight, |
| 66 | + isExpanded: true, |
| 67 | + decoration: InputDecoration( |
| 68 | + enabledBorder: InputBorder.none, |
| 69 | + ), |
| 70 | + icon: Icon( |
| 71 | + Icons.arrow_drop_down, |
| 72 | + color: ThemeBloc.theme(themeIndex) |
| 73 | + .textTheme |
| 74 | + .bodyLarge |
| 75 | + ?.color, |
| 76 | + size: 25, |
| 77 | + ), |
| 78 | + items: Languages.values |
| 79 | + .map((e) => DropdownMenuItem( |
| 80 | + value: e, |
| 81 | + child: Text(e), |
| 82 | + )) |
| 83 | + .toList(), |
| 84 | + onChanged: (newselectedLanguage) { |
| 85 | + Languages.forEach((key, value) { |
| 86 | + if (value == newselectedLanguage) { |
| 87 | + selectedLanguageCode = key; |
| 88 | + selectedLanguage = value; |
| 89 | + } |
| 90 | + }); |
| 91 | + }, |
| 92 | + value: selectedLanguage, |
| 93 | + ), |
| 94 | + )), |
| 95 | + ], |
| 96 | + ), |
| 97 | + SizedBox(height: 25), |
| 98 | + Row( |
| 99 | + children: [ |
| 100 | + Expanded(child: Container()), |
| 101 | + Expanded( |
| 102 | + child: Container( |
| 103 | + height: hp * 0.06, |
| 104 | + decoration: |
| 105 | + BoxDecoration(borderRadius: BorderRadius.circular(8)), |
| 106 | + child: ElevatedButton( |
| 107 | + onPressed: () async { |
| 108 | + if (selectedLanguage == 'Automatic') { |
| 109 | + BlocProvider.of<LanguageBloc>(context, |
| 110 | + listen: false) |
| 111 | + .add(ChangeLanguageEvent(null)); |
| 112 | + } else { |
| 113 | + BlocProvider.of<LanguageBloc>(context, |
| 114 | + listen: false) |
| 115 | + .add(ChangeLanguageEvent( |
| 116 | + Locale(selectedLanguageCode))); |
| 117 | + } |
| 118 | + await Future.delayed(Duration.zero); |
| 119 | + final setSpeedSnackbar = addFloodSnackBar( |
| 120 | + SnackbarType.information, |
| 121 | + l10n.settings_language_set_snackbar, |
| 122 | + l10n.button_dismiss, |
| 123 | + ); |
| 124 | + ScaffoldMessenger.of(context).clearSnackBars(); |
| 125 | + ScaffoldMessenger.of(context) |
| 126 | + .showSnackBar(setSpeedSnackbar); |
| 127 | + }, |
| 128 | + style: ElevatedButton.styleFrom( |
| 129 | + shape: RoundedRectangleBorder( |
| 130 | + borderRadius: BorderRadius.circular(8), |
| 131 | + ), |
| 132 | + backgroundColor: |
| 133 | + ThemeBloc.theme(themeIndex).colorScheme.secondary, |
| 134 | + ), |
| 135 | + child: Center( |
| 136 | + child: Text( |
| 137 | + l10n.button_set, |
| 138 | + style: TextStyle( |
| 139 | + color: Colors.white, |
| 140 | + fontSize: 16, |
| 141 | + fontWeight: FontWeight.w600, |
| 142 | + ), |
| 143 | + ), |
| 144 | + ), |
| 145 | + ), |
| 146 | + ), |
| 147 | + ), |
| 148 | + ], |
| 149 | + ), |
| 150 | + SizedBox(height: 25), |
| 151 | + ], |
| 152 | + ) |
| 153 | + ], |
| 154 | + ); |
| 155 | + }); |
| 156 | + } |
| 157 | +} |
0 commit comments