在我的演示应用程序中,我需要从服务器加载一个 2 JSON 文件。两个 JSON 中都有大量数据。在我的 Flutter 应用程序中,我使用 Future + async + await 调用 json,而不是使用 runApp 创建小部件。在正文中,我尝试激活 CircularProgressIndicator。它显示 appBar 及其内容以及空白页面正文,并在 4 或 5 秒后加载实际正文中的数据。
我的问题是我需要先显示 CircularProgressIndicator,一旦数据加载,我将调用 runApp()。我怎么做?
// MAIN
void main() async {
_isLoading = true;
// Get Currency Json
currencyData = await getCurrencyData();
// Get Weather Json
weatherData = await getWeatherData();
runApp(new MyApp());
}
// Body
body: _isLoading ?
new Center(child:
new CircularProgressIndicator(
backgroundColor: Colors.greenAccent.shade700,
)
) :
new Container(
//… actual UI
)