如何运行第一个flutter dio使用实例
2020-07-19 本文已影响0人
如非泽落
用as新建一个flutter项目
- 在perspec.yaml文件添加依赖
dio: ^3.0.9
- 将main.dart 修改为以下代码
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
void main() {
runApp(TabsPage());
}
class TabsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
getHttp();
return Scaffold(
body: Center(
child: Text('首页'),
),
);
}
void getHttp() async {
try{
Response response = await Dio().get(
'https://baidu.com'
);
return print(response);
}catch(e){
return print(e);
}
}
}
- 运行