InheritedWidget - The getter was called on null after navigator.push

后端 未结 2 1332
忘掉有多难
忘掉有多难 2021-02-14 07:42

I\'m having trouble trying to access an InheritedWidget after navigating to a new widget.

I have my top level widget like this

class App extends Statele         


        
相关标签:
2条回答
  • 2021-02-14 08:13

    In the code you've provided, LoginScreen is not a descendant of LoginBlocProvider which is why it can't find the ancestor widget. Your code wraps the WelcomeScreen route in LoginBlocProvider, but not the whole navigator. The solution is to wrap your MaterialApp in LoginBlocProvider and then you will have access to it everywhere in your app.

    class App extends StatelessWidget {
      @override
      Widget build(context) {
        return LoginBlocProvider(
          child: MaterialApp(
            title: 'Iniciar Sesion',
            home: WelcomeScreen(),
          ),
        );
      }
    }
    
    0 讨论(0)
  • 2021-02-14 08:14

    InheritedWidget should wrap the full MatrialApp widget (root widget)

    0 讨论(0)
提交回复
热议问题