这篇文章给大家介绍Flutter中怎么实现一个下拉刷新上拉加载功能,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
创新互联专业为企业提供
渠县网站建设、渠县做网站、渠县网站设计、渠县网站制作等企业网站建设、网页设计与制作、渠县企业网站模板建站服务,十余年
渠县做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
使用方法
添加依赖
dependencies: pull_to_refresh: ^1.5.7
导入包
import 'package:pull_to_refresh/pull_to_refresh.dart';
页面代码样例
class _MyHomePageState extends State { List items = ["1", "2", "3", "4", "5", "6", "7", "8"]; RefreshController _refreshController = RefreshController(initialRefresh: false); void _onRefresh() async { // monitor network fetch await Future.delayed(Duration(milliseconds: 1000)); // if failed,use refreshFailed() _refreshController.refreshCompleted(); } void _onLoading() async { // monitor network fetch await Future.delayed(Duration(milliseconds: 1000)); // if failed,use loadFailed(),if no data return,use LoadNodata() items.add((items.length + 1).toString()); if (mounted) setState(() {}); _refreshController.loadComplete(); } @override Widget build(BuildContext context) { return Scaffold( body: SmartRefresher( enablePullDown: true, enablePullUp: true, header: WaterDropHeader(), footer: CustomFooter( builder: (BuildContext context, LoadStatus mode) { Widget body; if (mode == LoadStatus.idle) { body = Text("pull up load"); } else if (mode == LoadStatus.loading) { body = CircularProgressIndicator(); } else if (mode == LoadStatus.failed) { body = Text("Load Failed!Click retry!"); } else if (mode == LoadStatus.canLoading) { body = Text("release to load more"); } else { body = Text("No more Data"); } return Container( height: 55.0, child: Center(child: body), ); }, ), controller: _refreshController, onRefresh: _onRefresh, onLoading: _onLoading, child: ListView.builder( itemBuilder: (c, i) => Card(child: Center(child: Text(items[i]))), itemExtent: 100.0, itemCount: items.length, ), ), ); }}
关于Flutter中怎么实现一个下拉刷新上拉加载功能就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
网页题目:Flutter中怎么实现一个下拉刷新上拉加载功能-创新互联
当前地址:
http://mswzjz.cn/article/dshsis.html