使用flutter_easyrefresh庫
本實體:flutter_easyrefresh版本: ^1.2.7
使用
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 MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
// App名字
title: 'EasyRefresh',
// App主題
theme: new ThemeData(
primarySwatch: Colors.orange,
),
// 主頁
home: BasicPage(),
);
}
}
class BasicPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _BasicPageState();
}
}
class _BasicPageState extends State<BasicPage> {
int kaishi = 0;
int number = 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(() {
List<dynamic> one = resalt_json['shuju'];
str.addAll(one);
});
}
List<String> addStr = [];
List<dynamic> str = [];
@override
Widget build(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: new Text(
str[index],
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(() {
List<dynamic> one = resalt_json['shuju'];
str.clear();
str.addAll(one);
});
});
},
loadMore: () async {
await new Future.delayed(const Duration(seconds: 1), () async {
this.kaishi++;
int offset=(kaishi-1)*number;
var resalt = await shuaxinmoban.resquest(
'/xzj1?start=$offset&count=$number',
method: shuaxinmoban.GET,
);
var resalt_json = JSON.jsonDecode(resalt);
setState(() {
List<dynamic> one = resalt_json['shuju'];
str.addAll(one);
});
});
},
)), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/170086.html
標籤:其他
上一篇:哈希函式(Hash Functions - 散列函式)的基本介紹(SHA-2,SHA-256,MD-5,Scrypt,BCrypt等)
下一篇:CLI 命令列實用程式開發基礎
