0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[メモ] asyncをどこで使ったか

Last updated at Posted at 2020-03-07

はじめに

こちらを参考にさせていただきました。

アプリ起動してウィジェットをbuildする前に現在地を取得

class _LoadingScreenState extends State<LoadingScreen> {
  @override
  void initState() {
    super.initState();
    // --- ここで使った ---
    getLocation();
    // ------------------
  }

  void getLocation() async {
    Position position = await Geolocator().getCurrentPosition(
      desiredAccuracy: LocationAccuracy.low,
    );
    print(position);
  }

await忘れててウィジェットつくれないやーつ

E/flutter (14324): This Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.

  void getLocationData() async {
    var weatherData = ★ここにawaitが必要★ WeatherModel().getLocationWeather();

    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return LocationScreen(
        locationWeather: weatherData,
      );
    }));
  }

Dataの取得中にウィジェットを作成しようとするというのは、つまり、プロセスが未完了のデータ(null)を受け取ろうとすることなのでウィジェットの作成に失敗する。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?