-
-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Language not changing #448
Comments
I got same issue too. |
Please more details ??! |
Please test with MaterialApp.router, you will see the language not refresh in UI when we change the language. It works fine in MaterialApp but not MaterialApp.router |
The solution that worked for me is the following: children: [
const ProfilePage();
const HomePage();
] The fix is to remove the children: [
// ignore: prefer_const_constructors
ProfilePage();
// ignore: prefer_const_constructors
HomePage();
] Every other widget inside HomePage or ProfilePage can be |
Yes you are awesome, saved my day, thank you. |
Do we have better workaround so we don't need to remove the |
Easy Localization uses bad practice - it doesn't utilize BuildContext. That's why your translations will never be updated if they are const. |
don't forget to delete the 'const' on MaterialApp child/home widget if it exists |
Same issue context.setLocale does not effect. Please help. |
To update the translations, since Easy_Localization doesn't use the context, just update the context of the EasyLocalization instance. With this solution I managed to fix this problem. My Code: Padding(
padding: const EdgeInsets.all(18.0),
child: DropdownButton(
items: context.supportedLocales
.map(
(e) => DropdownMenuItem(
value: e,
child: Text(
context.localizables.localeTitle(e.languageCode),
style: context.styles.h2Lato,
),
),
)
.toList(),
value: context.locale,
onChanged: (value) => value != null ? context.setLocale(value) : null,
),
), import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
extension LanguageLoader on BuildContext {
Localizable get localizables => Localizable(this);
}
class Localizable {
final BuildContext context;
Localizable(this.context);
String get appTitle => ltr('appTitle');
String get yes => ltr('yes');
String get no => ltr('no');
String get quoteAnime => ltr('quoteAnime');
String darkModeTitle(bool enabled) => ltr('darkModeTitle', args: [enabled ? yes : no]);
String localeTitle(String locale) => ltr('locale.$locale');
String ltr(
String key, {
List<String>? args,
Map<String, String>? namedArgs,
String? gender,
}) {
EasyLocalization.of(context);
return tr(key, args: args, namedArgs: namedArgs, gender: gender);
}
}
|
Duplicate of #552 |
I've went through other issues and this isn't like #370.
Application changes the direction of the language and the locale gets changed but the words of the application don't get changed they remain on the same language until I restart the application myself, it was working fine on the ^2.3.3 version before null safety and it changed instantly now I don't know what happened!
I've tried it on a normal application, using provider, and using bloc and it's the same issue
The text was updated successfully, but these errors were encountered: