import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class LearnHttp extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return new _LearnHttp();
}
}
class _LearnHttp extends State<LearnHttp>{
String httpResult="null";
@override
Widget build(BuildContext context) {
return new Scaffold(
body:new Container(
margin: EdgeInsets.all(20.0),
padding: EdgeInsets.all(10.0),
decoration: new BoxDecoration(
color: Colors.black,
border:new Border.all(
color: Colors.yellow,
width: 10.0,
),
),
child: new Center(
child:new SingleChildScrollView(
child: new Text(
httpResult,
style: new TextStyle(
color: Colors.white
),
),
),
),
),
floatingActionButton: new FloatingActionButton(
child: new Center(
child: new Text('发送请求',style: new TextStyle(
fontSize: 10.0,
color: Colors.yellow
),),
),
backgroundColor: Colors.red,
onPressed: (){
httpRequest();
}
),
);
}
void httpRequest(){
var url="http://www.wanandroid.com/article/list/1/json";
http.get(url).then((response){
setState(() {
httpResult=response.body;
});
});
}
}
flutter控件之Http
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- Xamarin XAML语言教程构建ControlTemplate控件模板 控件模板ControlTemplate...
- Celery 分布式的任务队列 与rabbitmq消息队列的区别与联系: rabbitmq 调度的是消息,而Cel...
- 2017年5月8号上午,李家堡乡党委书记武廷英,副书记王琦,副乡长张国彪等人深入选派村看望驻村干部,给驻村干部带去...
