简体   繁体   中英

Flutter/Dart iOS grey screen from unhandled http.post request on invalid url

I have the classical grey screen issue on iOS release build, but I can't figure out a solution to remove the error:

When the app is launched, the first operation is to do an async http request, however if the URL is invalid or the server unavailable, this will produce an error seen in web console as:

net::ERR_NAME_NOT_RESOLVED

In debug mode I have no errors displayed in the VSC console and you can see on my code that I am handling any possible the error:

dynamic fetchPost(url, Map<String, String>? args) async {
  try {
    var response = await http.post(
      Uri.parse(url),
      headers: {},
      body: args,
    );
    return response;
  } catch (e) {
    return false;
  }
}

Yet, if I build my app on iOS release this will produce a grey screen on start if the URL is invalid. Is there another way to do the same task without producing an error?

Thanks

Usually grey screen in flutter apps are because of render errors. Look anywhere for widgets which do not have a fixed height or width in your home page or your entry screen. Please share the entry point of your app and minimum reproducible code for further debugging.

Issue solved: the problem happened to be completely unrelated and about async loading of dependencies. The working results I had were because I was using constants values in place of actually calling a function that wasn't ready yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM