Flutter 实现下拉刷新上拉加载的示例代码
dependencies: pull_to_refresh:^1.5.7
导入包
import'package:pull_to_refresh/pull_to_refresh.dart';
页面代码样例
class_MyHomePageStateextendsState{ List items=["1","2","3","4","5","6","7","8"]; RefreshController_refreshController= RefreshController(initialRefresh:false); void_onRefresh()async{ //monitornetworkfetch awaitFuture.delayed(Duration(milliseconds:1000)); //iffailed,userefreshFailed() _refreshController.refreshCompleted(); } void_onLoading()async{ //monitornetworkfetch awaitFuture.delayed(Duration(milliseconds:1000)); //iffailed,useloadFailed(),ifnodatareturn,useLoadNodata() items.add((items.length+1).toString()); if(mounted)setState((){}); _refreshController.loadComplete(); } @override Widgetbuild(BuildContextcontext){ returnScaffold( body:SmartRefresher( enablePullDown:true, enablePullUp:true, header:WaterDropHeader(), footer:CustomFooter( builder:(BuildContextcontext,LoadStatusmode){ Widgetbody; if(mode==LoadStatus.idle){ body=Text("pullupload"); }elseif(mode==LoadStatus.loading){ body=CircularProgressIndicator(); }elseif(mode==LoadStatus.failed){ body=Text("LoadFailed!Clickretry!"); }elseif(mode==LoadStatus.canLoading){ body=Text("releasetoloadmore"); }else{ body=Text("NomoreData"); } returnContainer( 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, ), ), ); } }
完整源代码
https://gitee.com/cxyzy1/flutter_pulldown_refresh
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。