Jesway / flutter_translate

Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter.
MIT License
403 stars 118 forks source link

Default locale not set when reopen the app #82

Closed mohd-aidi closed 2 years ago

mohd-aidi commented 2 years ago

HI, this is awesome plugin. but i have an issue for when i set english and malay language but i want to set malay as default language.

but then after select malay as default locale, I close and reopen the app but the default always back to english.

when i changeLocale it works perfectly but it default back to english when i reopen the app.

can you help me?

Widget build(BuildContext context) { var localizationDelegate = LocalizedApp.of(context).delegate; return OverlaySupport( child: MaterialApp( debugShowCheckedModeBanner: false, title: translate('app_bar.title'), localizationsDelegates: [ localizationDelegate ], locale: Locale(localizationDelegate.currentLocale.languageCode), theme: ThemeData( scaffoldBackgroundColor: kBackgroundColor, primaryColor: kPrimaryColor, textTheme: Theme.of(context).textTheme.apply(bodyColor: kTextColor), visualDensity: VisualDensity.adaptivePlatformDensity, ), home: BlocProvider( create: (context) => AppCubits(), child: AppCubitLogics(), ) ) ); }

InkWell( onTap: (){ print(data); changeLocale(context, data); Navigator.pop(context); }, child: Card( elevation: 4, child: Padding( padding: const EdgeInsets.all(16.0), child: Text(translate('language.name.${data}'), style: TextStyle(fontSize: 22.0),), ), ), );

bratan commented 2 years ago

Check out this example for saving/restoring the selected language: https://github.com/bratan/flutter_translate/wiki/2.-Automatically-saving-&-restoring-the-selected-locale