【发布时间】:2020-05-02 11:28:19
【问题描述】:
我在颤振中有以下代码。在initialRoute: 属性中,它需要调用isLoggedIn() 方法,这是一个异步函数。我收到一条错误消息,提示我需要在 async 函数中调用 await。但是build 方法被其父类覆盖,而不是async 方法。如何在被覆盖的方法中调用 await?
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: '',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: await isLoggedIn() ? '/': '/login',
routes: <String, WidgetBuilder>{
'/': (BuildContext context) {
return MyHomePage(title: 'Home Page');
},
'/login': (BuildContext context) {
return Login();
},
}
);
}
}
【问题讨论】: