当我导入课程时
import 'package:http/http.dart' as http;
按照https://flutter.dev/docs/cookbook/networking/fetch-data
它给出错误目标URL不存在
答案 0 :(得分:0)
import 'package:http/http.dart' as http;
Future<http.Response> fetchPost() { return http.get('https://jsonplaceholder.typicode.com/posts/1'); }
在上面的示例中,目标网址是
相应的响应是
{ "userId": 1, "id": 1, "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" }
更多详细信息可用
答案 1 :(得分:0)
您必须将Http包添加到pubspec.yaml文件中的依赖项中,然后调用flutter包get
dependencies:
flutter:
sdk: flutter
cupertino_icons: 0.1.2
http: 0.12.0+2