import 'dart:collection';
import 'dart:convert' as JSON;
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:meituanwaimai/wangluoqingqiu/shuaxinmoban.dart';
void main() => runApp(MyApp());
class MyAppextends StatelessWidget {
@override
Widgetbuild(BuildContext context) {
return new MaterialApp(
// App名字
title:'EasyRefresh',
// App主题
theme:new ThemeData(
primarySwatch: Colors.orange,
),
// 主页
home:BasicPage(),
);
}
}
class BasicPageextends StatefulWidget {
@override
StatecreateState() {
return _BasicPageState();
}
}
class _BasicPageStateextends State {
intkaishi =0;
intnumber =5;
@override
void initState() {
// TODO: implement initState
super.initState();
qingqiu();
}
qingqiu()async {
var resalt =await shuaxinmoban.resquest(
'/xzj?start=$kaishi&count=$number',
method: shuaxinmoban.GET,
);
var resalt_json = JSON.jsonDecode(resalt);
setState(() {
str = resalt_json;
// str.addAll(more);
//print(str['1']['name']);
});
}
LinkedHashMapstr =new LinkedHashMap();
@override
Widgetbuild(BuildContext context) {
return Scaffold(
appBar:AppBar(
title:Text("EasyRefresh"),
),
body:Center(
child:new EasyRefresh(
child:new ListView.builder(
//ListView的Item
itemCount:str.length,
itemBuilder: (BuildContext context, int index) {
return new Container(
height:70.0,
child:Card(
child:new Center(
child:Row(
children: [
Text(
str[index.toString()].toString().split("+")[0],
style:new TextStyle(fontSize:18.0, color: Colors.red),
),
Text(
str[index.toString()].toString().split("+")[1],
style:new TextStyle(fontSize:18.0, color: Colors.red),
),
Text(
str[index.toString()].toString().split("+")[2],
style:new TextStyle(fontSize:18.0, color: Colors.red),
)
],
)
),
)
);
}),
onRefresh: ()async {
// //下拉请求新数据
await new Future.delayed(const Duration(seconds:1), ()async {
//this.kaishi++;
//int offset=(kaishi-1)*number;
var resalt =await shuaxinmoban.resquest(
'/xzj1?start=$kaishi&count=$number',
method: shuaxinmoban.GET,
);
var resalt_json = JSON.jsonDecode(resalt);
setState(() {
LinkedHashMap more = resalt_json;
str.clear();
str.addAll(more);
});
});
},
loadMore: ()async {
await new Future.delayed(const Duration(seconds:1), ()async {
this.kaishi++;
int offset=(kaishi)*number;
var resalt =await shuaxinmoban.resquest(
'/xzj1?start=$offset&count=$number',
method: shuaxinmoban.GET,
);
var resalt_json = JSON.jsonDecode(resalt);
setState(() {
LinkedHashMap more = resalt_json;
str.addAll(more);
});
});
},
)), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}