flutter 项目导入http.dart 包
void main() {
String dataUrl = 'https://jsonplaceholder.typicode.com/posts';
http.Response response = await http.get(dataUrl);
}
运行报如下错误:
The following Dart file:
/Users/lulu/AndroidStudioProjects1/flutter_app/lib/main.dart
...refers, in an import, to the following library:
package:http/http.dart
That library is in a package that is not known. Maybe you forgot to mention it in your pubspec.yaml file?
按照错误提示,在 pubspec.yaml中添加http依赖库即可
dependencies:
http: ^0.12.0
flutter:
sdk: flutter