final _navigatorKey = GlobalKey<NavigatorState>();
class MainApp extends StatefulWidget {
const MainApp({Key? key}) : super(key: key);
@override
_MainAppState createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
navigatorKey: _navigatorKey,
color: Colors.white,
getPages: router.routes,
initialRoute: SignInPageRoute,
routingCallback: (routing) {
final _navigationService = locator<NavigationService>();
final _authService = locator<AuthService>();
if (routing!.current == SignInPageRoute) {
WidgetsBinding.instance!.addPostFrameCallback(
(_) {
bool isLoggedIn = _authService.isLoggedIn();
if (isLoggedIn) {
_navigationService.offAllTo(MainPageRoute);
} else {
return;
}
},
);
}
});
}
}
试试这个
bool isLoggedIn = await _authService.isLoggedIn();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.