I added l10n to my flutter app as suggested in the flutter docs, it is suggested to get the localizations with a static method like this:
static DemoLocalizations of(BuildContext context) {
return Localizations.of<DemoLocalizations>(context, DemoLocalizations);
}
This works fine when running the app, but when I try to test my widgets, the returned value is always null.
Is there any easy way to provide the localizations within the tests?
For now I'm passing through the localizations via DI, but it is quite an overhead.
You can wrap the widget you want to tests into a Localizations
Localizations(
delegates: [
yourDelegate
],
locale: Locale('en'),
child: YourWidget(),
);
The above answer didn't help because I was calling strings from json
file. The medium blog actually handled my problem in solving the issue.
I think you should read this issues. In case file json over 10kb, it cannot load assets. We should keep following and wait Flutter team fix it or real solution https://github.com/flutter/flutter/issues/22193
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With