📜  由于 api 响应延迟导致的 null 错误 - Dart 代码示例

📅  最后修改于: 2022-03-11 14:48:03.047000             🧑  作者: Mango

代码示例2
String text;

fetchData() async {
//...
  text = weatherData.weather[0].main ?? 'Waiting api response...';
//...
}

// in your build method
@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Container(
      child: Text(text), //this will render "Waiting api response" first, and when the api result arrive, it will change
    ),
  );
}