Flutter EasyRefresh:介绍与使用指南
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<String> items = List<String>.generate(100, (i) => 'Item ${i + 1}');
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('EasyRefresh Example'),
),
body: EasyRefresh.custom(
slivers: <Widget>[
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return Container(
alignment: Alignment.center,
color: Colors.blue,
child: Text(
'${items[index]}',
style: TextStyle(color: Colors.white, fontSize: 16.0),
),
);
},
childCount: items.length,
),
),
],
refreshHeader: ClassicalHeader(
refreshText: '下拉刷新',
refreshingText: '正在刷新',
completeText: '刷新完成',
failedText: '刷新失败',
),
refreshFooter: ClassicalFooter(
loadText: '上拉加载更多',
loadingText: '正在加载...',
noMoreText: '没有更多数据了',
failedText: '加载失败',
),
onRefresh: () async {
await Future.delayed(Duration(seconds: 2));
setState(() {
items.addAll(List<String>.generate(10, (i) => 'New Item ${i + 1}'));
});
},
onLoad: () async {
await Future.delayed(Duration(seconds: 2));
setState(() {
items.addAll(List<String>.generate(10, (i) => 'New Item ${i + 1}'));
});
},
),
);
}
}
这段代码演示了如何在Flutter应用中使用EasyRefresh插件来为CustomScrollView添加下拉刷新和上拉加载更多的功
评论已关闭