Add point about initializing localization objects on 'Internationalizing Flutter apps' page #6424
Labels
e0-minutes
Effort: < 60 min
fix.bug
Needs fix of incorrect copy, code, or visual
from.page-issue
Reported in a reader-filed concern
p2-medium
Necessary but not urgent concern. Resolve when possible.
t.i18n
Relates to internationalization of Flutter apps
t.l10n
Relates to localizing Flutter text in apps
Page URL
https://docs.flutter.dev/accessibility-and-localization/internationalization
Page source
https://github.com/flutter/website/tree/main/src/docs/development/accessibility-and-localization/internationalization.md
Describe the problem
In the page, step 8, it is mentioned that
but I believe this is a bit misleading, because "anywhere" led me to naively think that this code was valid:
But it does not, because the localization objects are not yet initialized when the
AppLocalizations.of(context)!.helloWorld
is evaluated, so things crash with a null exception. It's simple to understand thatAppLocalizations.of(context)
is null in this instance, but it's not obvious that it is because it is uninitialized.Expected fix
I believe the documentation could be a little more clear and contextually mention (in point 7 or 8) that the material app has to actually be started to initialize the
AppLocalizations
and that usingAppLocalizations.of(context)!.helloWorld
won't work before that.In retrospective the error is clear, but a minor fix could help avoiding this problem at all.
Additional context
No response
The text was updated successfully, but these errors were encountered: