【发布时间】:2020-01-19 04:09:32
【问题描述】:
我正在尝试使用 HTTP 执行获取请求,只是为了获取 google 并将其显示为文本。
我的代码适用于 Android 和 iOS,但不适用于 Web。
String _google;
void _onClick() async {
final _res = await http.get('https://www.google.com');
print(_res.body);
setState(() => _google = _res.body);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(''),
),
body: Center(
child: Text(_google ?? 'null'),
),
floatingActionButton: FloatingActionButton(
onPressed: _onClick,
child: Icon(Icons.send),
),
);
}
【问题讨论】:
标签: flutter flutter-web