近年来各大公司对Flutter技能的要求愈来愈高,甚至设立了专门岗位,但掌握Flutter高阶技能的人才寥寥无几,市面上干货Flutter高阶课程少之又少,致使Flutter高阶人才缺口大。为此咱们专门为你们设计了这门课程,助力你早日成为企业抢手的新一代工程师json
课程的亮点:
从原理剖析到性能调优快速吸取Flutter精髓点亮高阶实践技能
从复杂APP业务需求出发遵循行业标准高度匹配大厂Flutter岗位技能需求
高阶人才不能只停留在开发总体架构设计→开发细节→效率工具方法带你完成真正的全盘思考服务器
Flutter 是 Google 用以帮助开发者在 iOS 和 Android 两个平台开发高质量原生 UI 的移动 SDK。Flutter 兼容现有的代码,免费且开源,在全球开发者中普遍被使用。本专栏将不按期更新 Flutter 相关高级学习教程。网络
Flutter的网络交互
用Flutter进行网络交互有四个步骤:架构
导入http库
使用http库建立网络请求
将服务器相应转换为一个自定义的Dart对象
将数据展现出来
导入http库
http库是Dart团队开发的方便网络请求的库,咱们须要在pubspec.yaml文件中引用它。工具
dependencies: http: <latest_version>
建立网络请求
有了网络请求库以后,接下来就该使用库进行网络请求了。post
好比GET请求:性能
Future<http.Response> fetchPost() { return http.get('https://jsonplaceholder.typicode.com/posts/1'); }
POST请求:学习
import 'package:http/http.dart' as http; var url = "http://example.com/whatsit/create"; http.post(url, body: {"name": "doodle", "color": "blue"}) .then((response) { print("Response status: ${response.statusCode}"); print("Response body: ${response.body}"); });
建立一个Client:fetch
var client = new http.Client(); client.post( "http://example.com/whatsit/create", body: {"name": "doodle", "color": "blue"}) .then((response) => client.get(response.bodyFields['uri'])) .then((response) => print(response.body)) .whenComplete(client.close);
增长UA:jsonp
class UserAgentClient extends http.BaseClient { final String userAgent; final http.Client _inner; UserAgentClient(this.userAgent, this._inner); Future<StreamedResponse> send(BaseRequest request) { request.headers['user-agent'] = userAgent; return _inner.send(request); } }