Closed vanhcoder closed 4 months ago
Hi @vanhcoder
Basically, go_router provides the ability to add the navigation key.
final _rootNavigatorKey = GlobalKey<NavigatorState>();
class AppRouter {
final goRouter = GoRouter(
navigatorKey: _rootNavigatorKey,
routes: [],
);
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
theme: DemoThemes.lightTheme,
routerConfig: AppRouter().goRouter
);
}
}
then you can use _rootNavigatorKey on the add_oauth as the same that you add on the go_router
// ...
static final Config config = new Config(
tenant: "YOUR_TENANT_ID",
clientId: "YOUR_CLIENT_ID",
scope: "openid profile offline_access",
// redirectUri is Optional as a default is calculated based on app type/web location
redirectUri: "your redirect url available in azure portal",
navigatorKey: _rootNavigatorKey,
webUseRedirect: true, // default is false - on web only, forces a redirect flow instead of popup auth
//Optional parameter: Centered CircularProgressIndicator while rendering web page in WebView
loader: Center(child: CircularProgressIndicator()),
postLogoutRedirectUri: 'http://your_base_url/logout', //optional
);
final AadOAuth oauth = new AadOAuth(config);
It's not working in a go_router redirect parameter:
Hi @vanhcoder
Basically, go_router provides the ability to add the navigation key.
final _rootNavigatorKey = GlobalKey<NavigatorState>(); class AppRouter { final goRouter = GoRouter( navigatorKey: _rootNavigatorKey, routes: [], ); } class MainApp extends StatelessWidget { const MainApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp.router( debugShowCheckedModeBanner: false, theme: DemoThemes.lightTheme, routerConfig: AppRouter().goRouter ); } }
then you can use _rootNavigatorKey on the add_oauth as the same that you add on the go_router
// ... static final Config config = new Config( tenant: "YOUR_TENANT_ID", clientId: "YOUR_CLIENT_ID", scope: "openid profile offline_access", // redirectUri is Optional as a default is calculated based on app type/web location redirectUri: "your redirect url available in azure portal", navigatorKey: _rootNavigatorKey, webUseRedirect: true, // default is false - on web only, forces a redirect flow instead of popup auth //Optional parameter: Centered CircularProgressIndicator while rendering web page in WebView loader: Center(child: CircularProgressIndicator()), postLogoutRedirectUri: 'http://your_base_url/logout', //optional ); final AadOAuth oauth = new AadOAuth(config);
Thank bro, it work!!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you still think this issue is needed, reopen it again.
false
In 'aad_oauth' library, it's necessary to pass the navigatorKey to MaterialApp(), but in recent versions, when combined with route libraries like auto_router, go_router, it's required to use MaterialApp.router, and MaterialApp.router does not support the navigatorKey parameter. So what's the solution here?"