Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type 'DefaultWidgetsLocalizations' is not a subtype of type 'I18n' #20

Open
Tridie2000 opened this issue Jul 22, 2019 · 4 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@Tridie2000
Copy link

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?

@Tridie2000
Copy link
Author

Tridie2000 commented Jul 22, 2019

download demo project

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),
      ),
    );
  }
}

@esskar esskar self-assigned this Jul 24, 2019
@esskar esskar added the bug Something isn't working label Jul 24, 2019
@esskar
Copy link
Owner

esskar commented Jul 24, 2019

Hi, back from vacation. Will have a look.

@abumalick
Copy link

Yes, I have the same error, did you find a solution?

@abumalick
Copy link

I think it happens when we forget to add supportedLocales, after adding it everything worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants