vscode-flutter-i18n-json
vscode-flutter-i18n-json copied to clipboard
type 'DefaultWidgetsLocalizations' is not a subtype of type 'I18n'
Sometimes I get this error. The only way to work around the issue is by passing the context of the main screen of the app. This results in a very complex codebase. If I change I18n.of(context).text
to MaterialLocalizations.of(context).cancelButtonLabel
, it works just fine. What could be the reason for this and is there an easy way to fix it?
I made a demo project showing you how to reproduce this error. It includes this code:
class FrameScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text('Localization'),
bottom: TabBar(
tabs: <Widget>[
Tab(
child: Text('1'),
),
Tab(
child: Text('2'),
),
],
),
),
body: TabBarView(
children: <Widget>[
MyHomePage(
title: 'Test',
),
Container(),
],
),
),
),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(I18n.of(context).pushed),
//Text(MaterialLocalizations.of(context).cancelButtonLabel),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Hi, back from vacation. Will have a look.
Yes, I have the same error, did you find a solution?
I think it happens when we forget to add supportedLocales
, after adding it everything worked for me