Best approach to null safe AppLocalization strings

If you are sure, that AppLocalizations.of(context) will always return a valid AppLocalizations instance (which is true for your sample application), you can use:

AppLocalizations.of(context)!.myString

The ! operator tells Dart, that AppLocalizations.of(context) will never return null and acts like a cast from the nullable AppLocalizations? to the non-nullable AppLocalizations.

Note: If AppLocalizations.of(context) returns null at runtime, then AppLocalizations.of(context)! will throw an exception.


add this line in l10n.yaml:

nullable-getter: false