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

后端 未结 2 1330
忘掉有多难
忘掉有多难 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(),
          ),
        );
      }
    }
    

提交回复
热议问题