SmartRefresher class

这是提供下拉刷新和上拉加载功能的核心组件。 RefreshController 不能为空,每个 SmartRefresher 只能对应一个控制器。

Header 指示器:已内置多种样式,包括 ClassicHeader、WaterDropMaterialHeader、MaterialClassicHeader 等。 Footer 指示器:已内置 ClassicFooter。 自定义指示器:如果需要自定义样式,可以使用 CustomHeader 或 CustomFooter。

使用示例:

SmartRefresher(
  controller: _refreshController,
  enablePullDown: true,
  enablePullUp: true,
  header: ClassicHeader(),
  footer: ClassicFooter(),
  onRefresh: () async {
    // 执行刷新逻辑
    await Future.delayed(Duration(seconds: 1));
    _refreshController.refreshCompleted();
  },
  onLoading: () async {
    // 执行加载更多逻辑
    await Future.delayed(Duration(seconds: 1));
    _refreshController.loadComplete();
  },
  child: ListView.builder(
    itemCount: 20,
    itemBuilder: (context, index) {
      return ListTile(title: Text('Item $index'));
    },
  ),
);

相关组件:

Inheritance

Constructors

SmartRefresher({Key? key, required RefreshController controller, Widget? child, Widget? header, Widget? footer, bool enablePullDown = true, bool enablePullUp = false, VoidCallback? onRefresh, VoidCallback? onLoading, DragStartBehavior? dragStartBehavior, bool? primary, double? cacheExtent, int? semanticChildCount, bool? reverse, ScrollPhysics? physics, Axis? scrollDirection, ScrollController? scrollController})
创建一个带有下拉刷新和上拉加载功能的组件
const
SmartRefresher.builder({Key? key, required RefreshController controller, required RefresherBuilder? builder, bool enablePullDown = true, bool enablePullUp = false, VoidCallback? onRefresh, VoidCallback? onLoading})
创建一个带有下拉刷新和上拉加载功能的组件,使用自定义构建器
const

Properties

builder → RefresherBuilder?
自定义内容构建器
final
cacheExtent → double?
缓存区域大小(复制自 ScrollView)
final
child → Widget?
刷新内容组件
final
controller → RefreshController
控制内部状态的控制器
final
dragStartBehavior → DragStartBehavior?
拖动开始行为(复制自 ScrollView)
final
enablePullDown → bool
是否启用下拉刷新功能
final
enablePullUp → bool
是否启用上拉加载更多功能
final
底部加载更多指示器
final
hashCode → int
The hash code for this object.
no setterinherited
头部刷新指示器
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onLoading → VoidCallback?
上拉加载更多回调
final
onRefresh → VoidCallback?
下拉刷新回调
final
physics → ScrollPhysics?
滚动物理效果(复制自 ScrollView)
final
primary → bool?
是否使用 primary scroll controller(复制自 ScrollView)
final
reverse → bool?
是否反向滚动(复制自 ScrollView)
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scrollController → ScrollController?
滚动控制器(复制自 ScrollView)
final
scrollDirection → Axis?
滚动方向(复制自 ScrollView)
final
semanticChildCount → int?
语义化子组件数量(复制自 ScrollView)
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<StatefulWidget>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

of(BuildContext? context) → SmartRefresher?
ofState(BuildContext? context) → SmartRefresherState?