在Flutter中,很容易使用url_launcher(图A )将用户带到网站。我正在寻找一种在完成/失败后返回HTTP状态代码的方法。理想情况下,将其以字符串形式返回以输出文本。
图A;
_launchURL() async {
const url = 'https://google.com/';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
谢谢
答案 0 :(得分:1)
import 'package:http/http.dart' as http;
void _loadFromUrl(String url) async {
http.Response response = await http.get(url);
if (response.statusCode == 200) {...}
else {...}
希望对您有帮助