Комментарии:
Good practice tip for everyone:
Create an extension like so you can access the translation values like Text(context.locale.yourTranslation)
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
extension LocalizationsExtensions on BuildContext {
AppLocalizations get locale => AppLocalizations.of(this)!;
}
You can set also for other situations like access the Theme.of(context) colors properties:
import 'package:flutter/material.dart';
extension BuildContextExtensions on BuildContext {
ThemeData get theme => Theme.of(this);
TextTheme get textTheme => theme.textTheme;
ColorScheme get colorScheme => theme.colorScheme;
Color get backgroundColor => colorScheme.background;
Color get cardColor => theme.cardColor;
}
from Theme.of(context).colorScheme.background
to context.backgroundColor
:))))))
is the description mandatory? @HeyFlutter
ОтветитьVery helpful and informative. Thanks
ОтветитьA very nice tutorial there. Always strainght forward. I like it. Keep up.
But pease, I tested your approach on Flutter web and it works like charm but I noticed that when ever I purposely reload the tab the locale is reseted to the system's locale. It doesn't take into consideration if it there were any changes before. Is there any way to persist the locale value after calling setLocale ?
Thanks
Ich darf Dir mitteilen, dass ich aufgrund deiner Kurse programmieren gelernt habe. Dafür darf ich mich bedanken.
Ответитьvery clear and tuff understanding with easy explaining thank you HeyFlutter
ОтветитьHow to modify the code to add supportedScript? I tried to add translations, add supportedScript in the list of languages, but it is not working.
Also returned Locale.subfromSubtags(), but seems it is not working.
no Israel it is Palestine
Ответитьyou are THE BEST 👌
ОтветитьSchönes und hilfreiches Video.
Ответитьhow to translate data inside listView builder can someone help..?
Ответитьany short way to use AppLocalizations.of(context)!.languagein every page?
ОтветитьIts showing me error when i add import statement @Johannes Milke Can you help what i did wrong
Ответитьplz help ..........AppLocalizations.of(context) getting null why?
Ответитьworked! many thanks
ОтветитьExcellent explaination
Ответитьi can't use fr_FR code even when change my file name to app_fr_FR it cause an error arb not found, I tried this because when I set locale to null the app not used the system language so I tries to get it with Platform.localeName
Ответитьin-app-purchase video plz
ОтветитьIn my case my flutter gen folder is changed to generated and AppLocalization.delegate is changed to S.delegate, and lastly app_en.arb is changed to intl_en.arb, apart from these changes, it works superb, thank you :)
ОтветитьFantastic explanation!
ОтветитьIf I want to make German as my default app language, How can I achieve this case ?
ОтветитьIt's not showing any .dart_tool file
Ответитьhi Milke, such a great tutorial. But i have a question. How can we combine this with remote languages and words ? Thanks you
ОтветитьHum, long step and lots of files to do this, useful if your app doesn't need internet but will give increase App size, what I do if internet connection is necessary is send I payload with language code and reseive the translation from server, async is your friend and small footprint size for ur app.
ОтветитьHow can I fix the Flutter_localizations error on the Android Studio? - Target of URI doesn't exist
Error setting-up flutter_localizations package "Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'."
Please give a solution as soon as possible
Thank You!
Thank you so much for this .Really love you bruh🥰😘😘😘😍💖💖
Ответитьdude you're so amazing, thank you very much
Ответитьby this i am able to change language in one page what if i want that language to reflect in all the app?
Ответитьthank you for the great tutorial, But I have a question, do you have any video that shows how to remember selected language after closing the application and reopening it ? your tutorial works fine but every time i close the application and open it it will go back to default language
ОтветитьThank you!! This helped me a lot. Nice tutorial!
Ответитьneed help ..getting error
String getTranslate(BuildContext context, String key) {
return AppLocalizations.of(context).helloWorld;
}
The getter 'helloWorld' was called on null.
Receiver: null
Tried calling: helloWorld
A value of type 'Null' can't be assigned to a variable of type 'Locale'.
ОтветитьHello, thanks for this awesome tutorial, i tried your tuto, but I have problem,
after each restart of app, it's give me the default locale, how i can save the selected language and use it ?
Thank you very much for this! Easy to follow instructions on the latest way to handle localization.
ОтветитьVery useful video,
Thanks.
Hello, i want to ask sth about the arb file.
As I have to generate language for simplified chinese which requires a locale with country code. But then when I build the project, an error told me I have to create a base arb file. So i have app_zh.arb and app_zh_CN.arb.
But inside the generated files, I can only find the app_localizations_zh.dart. Do you know what am i missing?
Your tutorial save my life. thank you
ОтветитьHi Johannas, Great tutorial.
Can you please make a tutorial for reading and opening all app notifications. It will be very helpful.
Thanks.
Great tutorial! But I've got this error :"Exception has occurred.
_CastError (Null check operator used on a null value)" .Flutter suggest to add "!" like this "AppLocalizations.of(context)!.appName " but it generates the error.Did you had it?
Good but there is no israel , it's palestine
ОтветитьThanks mate!
ОтветитьThis is great thank you. Can you teach us how to save the language preference in shared pref so load up would work? Now with your code I believe once we kill the app, it will reset back to default system local. If you save the local, then loading local from shared pref would be async and it would be slow on app start up.
ОтветитьYou are great👍😊👏
ОтветитьPlease Brother,
Make series on Bloc
I love your videos Man . However i face some issue about The getter 'value' was called on null
Ответитьsir if my mobile default language is english but i want to show spanish language first time i open the app
Ответить