From a2d425bb948cfe3d9ae38c423a9ac5efbedb34dd Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 3 Apr 2024 14:25:41 +0545 Subject: [PATCH] improve locale --- lib/src/features/home_screen/home_screen.dart | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/src/features/home_screen/home_screen.dart b/lib/src/features/home_screen/home_screen.dart index cd0e6d6..8d83f8d 100644 --- a/lib/src/features/home_screen/home_screen.dart +++ b/lib/src/features/home_screen/home_screen.dart @@ -37,15 +37,15 @@ class _HomeScreenState extends State { ), Consumer(builder: (context, ref, child) { var locale = ref.watch(localeConfigProvider); - return DropdownButton( + return DropdownButton( underline: const SizedBox( height: 0, ), elevation: 0, - value: locale.languageCode == 'ne' ? 1 : 2, + value: locale.languageCode, items: [ DropdownMenuItem( - value: 1, + value: 'ne', child: Flag.fromCode( FlagsCode.NP, height: 24, @@ -53,7 +53,7 @@ class _HomeScreenState extends State { ), ), DropdownMenuItem( - value: 2, + value: 'us', child: Flag.fromCode( FlagsCode.US, width: 24, @@ -62,15 +62,8 @@ class _HomeScreenState extends State { ), ], onChanged: (value) { - switch (value) { - case 1: - locale = const Locale('ne', 'np'); - break; - case 2: - default: - locale = Locale(Intl.systemLocale); - break; - } + if (value == null) return; + locale = Locale(value, value == 'ne' ? 'np' : 'us'); ref.read(localeConfigProvider.notifier).setLocale(locale); }); }),