As the title said, if the widget class is extended from StatelessWidget
Localizations.of<MaterialLocalizations>(context, MaterialLocalizations);
will return null any ideas?
had the same problem. Theres an open github issue in the flutter repository. Only thing that solved it for me was creating a separat widget like this:
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
localizationsDelegates: [...],
supportedLocales: ..,
locale: ...,
home: MyAppPage()); // separat MyAppPage instead of putting widget code with translations here
}
// MyAppPage
class MyAppPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
...
body: Center(
child: Text(AppTranslations.of(context).translate(...)),
If this is not solving your problem we maybe need to see more code :)!
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