Aas*_*hiq 1 dependencies http flutter
我是flutter的新手,我尝试在我的应用程序中使用http依赖项,步骤如下,
1.在pubspec.yaml文件中导入
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
http: ^0.12.1
Run Code Online (Sandbox Code Playgroud)
2)然后我运行, >flutter pub get,command,
import 'package:http/http.dart';
class Homepage extends StatefulWidget {
@override
_HomepageState createState() => _HomepageState();
}
class _HomepageState extends State<Homepage> {
var url = "http://jsonplaceholder.typicode.com/photos";
// Used to initialize something before starting of the screen
@override
void initState() {
// TODO: implement initState
super.initState();
fetchdata();
}
fetchdata() async {
var res = await http.get(url);
print(res);
}
Run Code Online (Sandbox Code Playgroud)
从下面的代码中可以看出,我想从 URL 获取响应并想打印响应,我什至在这之后重新启动了我的 IDE,但它没有出现,错误消息是,
编译器消息:lib/pages/home_page.dart:22:21:错误:未为类“_HomepageState”定义 getter“http”。
- '_HomepageState' 来自 'package:first_app/pages/home_page.dart' ('lib/pages/home_page.dart')。尝试将名称更正为现有 getter 的名称,或定义名为“http”的 getter 或字段。var res = await http.get(url);
这只是我知道的一个简单错误,但这对我来说将是一个很大的帮助,提前致谢!
| 归档时间: |
|
| 查看次数: |
2032 次 |
| 最近记录: |