How do I call async property in Widget build method

前端 未结 3 1102
-上瘾入骨i
-上瘾入骨i 2020-12-06 16:38

I\'m new to Flutter and Dart, and I\'m trying to build a Flutter app which displays the device information on the screen. For this purpose I\'m trying to use this library: \

3条回答
  •  不思量自难忘°
    2020-12-06 17:04

    build() expects a sync result, so using async/await is inappropriate in build().

    Either use FutureBuilder where you return a placeholder Container() while the async result is not yet available or move the async code to initState() and update the state using setState when the value becomes available to have the build be executed again.

提交回复
热议问题