From 421601291f589533ba29df60e83bd86a84c176e5 Mon Sep 17 00:00:00 2001 From: BS851 Date: Thu, 5 May 2022 18:43:08 +0600 Subject: [PATCH 1/2] Multi language support implemented, alert dialouge implemented --- android/app/build.gradle | 4 +- android/app/src/main/AndroidManifest.xml | 1 + lib/app/core/values/text_styles.dart | 6 ++ lib/app/core/widget/alert_widget.dart | 58 +++++++++++++++++++ .../modules/favorite/views/favorite_view.dart | 6 +- lib/app/modules/home/views/home_view.dart | 2 +- .../modules/main/views/bottom_nav_bar.dart | 2 +- .../controllers/settings_controller.dart | 13 ++++- .../modules/settings/views/settings_view.dart | 56 ++++++++++++++++-- lib/l10n/app_bn.arb | 10 +++- lib/l10n/app_en.arb | 10 +++- pubspec.lock | 9 ++- 12 files changed, 161 insertions(+), 16 deletions(-) create mode 100644 lib/app/core/widget/alert_widget.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index e727b0af..e43416b0 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -60,7 +60,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 30 + compileSdkVersion 31 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -70,7 +70,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.hellohasan.flutter_getx_template" minSdkVersion 19 - targetSdkVersion 30 + targetSdkVersion 31 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 49559808..ec5c4258 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -8,6 +8,7 @@ android:icon="@mipmap/ic_launcher"> InkWell( + child: controller.selectedLangCode.contains('en') + ? const Icon(Icons.radio_button_checked) + : const Icon(Icons.radio_button_off), + onTap: () { + controller.updateLanguage('en'); + }, + )), + const SizedBox(width: 8.0,), + const Text( + 'English', + style: settingsItemStyle, + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.only(left: 18.0, bottom: 0.0), + child: Row(children: [ + Obx( + () => InkWell( + child: controller.selectedLangCode.contains('bn') + ? const Icon(Icons.radio_button_checked) + : const Icon(Icons.radio_button_off), + onTap: () { + controller.updateLanguage('bn'); + }, + ), + ), + const SizedBox(width: 8.0,), + const Text('বাংলা', style: settingsItemStyle), + ]), + ), + ], + ); + } + +} \ No newline at end of file diff --git a/lib/app/modules/favorite/views/favorite_view.dart b/lib/app/modules/favorite/views/favorite_view.dart index f298235b..68000b55 100644 --- a/lib/app/modules/favorite/views/favorite_view.dart +++ b/lib/app/modules/favorite/views/favorite_view.dart @@ -9,15 +9,15 @@ class FavoriteView extends BaseView { @override PreferredSizeWidget? appBar(BuildContext context) { return CustomAppBar( - appBarTitleText: 'Favorite', + appBarTitleText: appLocalization.bottomNavFavorite, ); } @override Widget body(BuildContext context) { - return const Center( + return Center( child: Text( - 'FavoriteView is working', + appLocalization.favoriteViewMessage, style: titleStyle, ), ); diff --git a/lib/app/modules/home/views/home_view.dart b/lib/app/modules/home/views/home_view.dart index 04e01166..857e6c2b 100644 --- a/lib/app/modules/home/views/home_view.dart +++ b/lib/app/modules/home/views/home_view.dart @@ -16,7 +16,7 @@ class HomeView extends BaseView { @override PreferredSizeWidget? appBar(BuildContext context) { return CustomAppBar( - appBarTitleText: 'GetX Templates on GitHub', + appBarTitleText: appLocalization.homeViewAppBarTitle, ); } diff --git a/lib/app/modules/main/views/bottom_nav_bar.dart b/lib/app/modules/main/views/bottom_nav_bar.dart index 611e464a..cae5c2cc 100644 --- a/lib/app/modules/main/views/bottom_nav_bar.dart +++ b/lib/app/modules/main/views/bottom_nav_bar.dart @@ -16,7 +16,7 @@ class BottomNavBar extends StatelessWidget { BottomNavBar({Key? key, required this.onNewMenuSelected}) : super(key: key); late AppLocalizations appLocalization; - final navController = BottomNavController(); + final navController = Get.put(BottomNavController()); final Key bottomNavKey = GlobalKey(); diff --git a/lib/app/modules/settings/controllers/settings_controller.dart b/lib/app/modules/settings/controllers/settings_controller.dart index 8b7201b9..74409126 100644 --- a/lib/app/modules/settings/controllers/settings_controller.dart +++ b/lib/app/modules/settings/controllers/settings_controller.dart @@ -1,9 +1,18 @@ +import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import '/app/core/base/base_controller.dart'; class SettingsController extends BaseController { - final count = 0.obs; + var selectedLangCode = "en".obs; - void increment() => count.value++; + updateLanguage(var langCode){ + print("Tapped: $langCode"); + selectedLangCode.value = langCode; + } + + void changeLanguage() { + var locale = selectedLangCode.value == 'en' ? Locale('en', 'US') : Locale('bn', 'BD'); + Get.updateLocale(locale); + } } diff --git a/lib/app/modules/settings/views/settings_view.dart b/lib/app/modules/settings/views/settings_view.dart index 734131cd..361862bb 100644 --- a/lib/app/modules/settings/views/settings_view.dart +++ b/lib/app/modules/settings/views/settings_view.dart @@ -1,10 +1,17 @@ import 'package:flutter/material.dart'; +import 'package:flutter_getx_template/app/core/values/app_colors.dart'; +import 'package:flutter_getx_template/app/core/values/text_styles.dart'; +import 'package:flutter_getx_template/app/core/widget/alert_widget.dart'; +import 'package:get/get.dart'; +import '../../main/controllers/bottom_nav_controller.dart'; import '/app/modules/settings/widgets/item_settings_widgets.dart'; import '/app/core/base/base_view.dart'; import '/app/core/widget/custom_app_bar.dart'; import '/app/modules/settings/controllers/settings_controller.dart'; class SettingsView extends BaseView { + BottomNavController bottomNavController = Get.find(); + @override PreferredSizeWidget? appBar(BuildContext context) { return CustomAppBar( @@ -47,15 +54,56 @@ class SettingsView extends BaseView { } void _onThemeItemClicked() { - showToast('Theme: Development in progress'); + showToast(appLocalization.themeToast); } void _onLanguageItemClicked() { - showToast('Language: Development in progress'); + Get.defaultDialog( + title: appLocalization.languageSelectorTitle, + titleStyle: titleStyle, + middleText: '', + content: AlertWidget(), + actions: [ + Padding( + padding: const EdgeInsets.only(right: 8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + InkWell( + child: Text( + appLocalization.cancelText, + style: settingsItemStyle, + ), + onTap: () { + Get.back(); + }, + ), + const SizedBox( + width: 16.0, + ), + ElevatedButton( + onPressed: () { + Get.back(); + controller.changeLanguage(); + bottomNavController.updateSelectedIndex(2); + showToast(appLocalization.languageToast); + }, + child: Text( + appLocalization.confirmText, + style: buttonTextStyle, + ), + style: ElevatedButton.styleFrom( + primary: AppColors.appBarColor, + ), + ), + ], + ), + ) + ], + ); } void _onFontSizeItemClicked() { - showToast('Font Size: Development in progress'); + showToast(appLocalization.fontSizeToast); } - } diff --git a/lib/l10n/app_bn.arb b/lib/l10n/app_bn.arb index 32c6cfb5..0c3c1bab 100644 --- a/lib/l10n/app_bn.arb +++ b/lib/l10n/app_bn.arb @@ -5,5 +5,13 @@ "titleOtherView": "অন্যান্য", "settingsTheme": "থিম", "settingsLanguage": "ভাষা", - "settingsFontSize": "অক্ষরের আকার" + "settingsFontSize": "অক্ষরের আকার", + "languageToast": "ভাষা: ভাষা পরিবর্তন হয়েছে", + "fontSizeToast": "অক্ষরের আকার: অক্ষরের আকার পরিবর্তনের কাজ চলছে", + "themeToast": "থিম: থিম পরিবর্তনের কাজ চলছে", + "favoriteViewMessage": "ফেভারিট স্ক্রিন এর কাজ চলছে", + "homeViewAppBarTitle": "GitHub এর GetX টেমপ্লেটসমূহ", + "languageSelectorTitle": "ভাষা নির্বাচন", + "cancelText": "বাতিল করুন", + "confirmText": "নিশ্চিত করুন" } \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 0971dfe8..a4228300 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -5,5 +5,13 @@ "titleOtherView": "OtherView", "settingsTheme": "Theme", "settingsLanguage": "Language", - "settingsFontSize": "Font Size" + "settingsFontSize": "Font Size", + "languageToast": "Language: Language Changed", + "fontSizeToast": "Font Size: Development in progress", + "themeToast": "Theme: Development in progress", + "favoriteViewMessage": "FavoriteView is working", + "homeViewAppBarTitle": "GetX Templates on GitHub", + "languageSelectorTitle": "Select Language", + "cancelText": "Cancel", + "confirmText": "Confirm" } \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 7d91dc6d..03733025 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -343,6 +343,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" meta: dependency: transitive description: @@ -613,7 +620,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.3" + version: "0.4.8" typed_data: dependency: transitive description: From 89e1bbb819e9c2e710e8cc2b7df4d0ba2b2bdf41 Mon Sep 17 00:00:00 2001 From: BS851 Date: Tue, 17 May 2022 13:06:21 +0600 Subject: [PATCH 2/2] requested changes implemented. Cancel button updated, Radio button tap area increase to both Text and button --- lib/app/core/widget/alert_widget.dart | 38 ++++++++++++------- .../modules/settings/views/settings_view.dart | 11 ++++-- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/lib/app/core/widget/alert_widget.dart b/lib/app/core/widget/alert_widget.dart index cfdbf3b3..7dbdb16c 100644 --- a/lib/app/core/widget/alert_widget.dart +++ b/lib/app/core/widget/alert_widget.dart @@ -19,17 +19,24 @@ class AlertWidget extends StatelessWidget { child: Row( children: [ Obx(() => InkWell( - child: controller.selectedLangCode.contains('en') - ? const Icon(Icons.radio_button_checked) - : const Icon(Icons.radio_button_off), + child: controller.selectedLangCode.contains('en') + ? const Icon(Icons.radio_button_checked) + : const Icon(Icons.radio_button_off), + onTap: () { + controller.updateLanguage('en'); + }, + )), + const SizedBox( + width: 8.0, + ), + InkWell( onTap: () { controller.updateLanguage('en'); }, - )), - const SizedBox(width: 8.0,), - const Text( - 'English', - style: settingsItemStyle, + child: const Text( + 'English', + style: settingsItemStyle, + ), ), ], ), @@ -38,7 +45,7 @@ class AlertWidget extends StatelessWidget { padding: const EdgeInsets.only(left: 18.0, bottom: 0.0), child: Row(children: [ Obx( - () => InkWell( + () => InkWell( child: controller.selectedLangCode.contains('bn') ? const Icon(Icons.radio_button_checked) : const Icon(Icons.radio_button_off), @@ -47,12 +54,17 @@ class AlertWidget extends StatelessWidget { }, ), ), - const SizedBox(width: 8.0,), - const Text('বাংলা', style: settingsItemStyle), + const SizedBox( + width: 8.0, + ), + InkWell( + onTap: () { + controller.updateLanguage('bn'); + }, + child: const Text('বাংলা', style: settingsItemStyle)), ]), ), ], ); } - -} \ No newline at end of file +} diff --git a/lib/app/modules/settings/views/settings_view.dart b/lib/app/modules/settings/views/settings_view.dart index 361862bb..1cc780af 100644 --- a/lib/app/modules/settings/views/settings_view.dart +++ b/lib/app/modules/settings/views/settings_view.dart @@ -69,17 +69,20 @@ class SettingsView extends BaseView { child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - InkWell( + ElevatedButton( child: Text( appLocalization.cancelText, - style: settingsItemStyle, + style: buttonTextStyle, + ), + style: ElevatedButton.styleFrom( + primary: AppColors.appBarColor, ), - onTap: () { + onPressed: () { Get.back(); }, ), const SizedBox( - width: 16.0, + width: 4.0, ), ElevatedButton( onPressed: () {