Flutter - 从 url_launcher 获取 HTTP 响应

Flutter - Getting HTTP Response from url_launcher

在 Flutter 中,使用 url_launcherFIG A)可以很容易地将用户带到一个网站。我正在寻找一种在完成/失败时 return HTTP 状态代码的方法。理想情况下,这将被 returned 在一个字符串中用于文本输出。

图A;

_launchURL() async {
  const url = 'https://google.com/';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

谢谢

import 'package:http/http.dart' as http;

void _loadFromUrl(String url) async {
  http.Response response = await http.get(url);
  if (response.statusCode == 200) {...}
  else {...}

希望对您有所帮助