0

I am using MSAL to authenticate users, with a ChangeNotifierProvider. I am trying to navigate to another page from the MSAL login but Navigator.push needs to be used in a widget. How do i navigate to another page without using Navigator.push? Or is it not available for flutter?

Code below:

void main() => runApp(
MultiProvider(
  providers: [
    ChangeNotifierProvider(create: (_)  => MsalProvider())
  ],
     child: MyApp(),
  )
);

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return CupertinoApp(
    home: Consumer(
        builder: (BuildContext context, MsalProvider msal, Widget _){
          // print(msal.status);
          switch(msal.status){
            case AuthStatus.AUTHENTICATED_USER:
              return MaterialPageRoute(builder: (context)=> UASRegistered()); // does not work, error says need a widget
          }
        }
    ));
  }
}
Wei Xiong
  • 167
  • 4
  • 13
  • You say that Navigator.push needs to be done inside a widget, but I've been using it in functions without a problem... As long as you pass the context into the function, you shouldn't have an problem with putting the navigator.push wherever you want in your program. – ArthurEKing Feb 13 '20 at 17:15
  • could you show me an example? @ArthurEKing – Wei Xiong Feb 15 '20 at 15:14

0 Answers0