[JAVA] [Note] Where did you use async?

Introduction

I used this as a reference.

Get your current location before launching the app and building the widget

class _LoadingScreenState extends State<LoadingScreen> {
  @override
  void initState() {
    super.initState();
    // ---Used here---
    getLocation();
    // ------------------
  }

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

I forgot await and can't make a widget

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 is required here ★ WeatherModel().getLocationWeather();

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

Attempting to create a widget while retrieving Data means that the process will try to receive incomplete data (null) and the widget creation will fail.

Recommended Posts

[Note] Where did you use async?
A note on what you did to use Flycheck with Python
Note until you use emacs with WSL
Where are you from
[Free to use] 7 learning sites where you can study Python