flutter_easy_refresh在3.38.3配合NestedScrollView的注意要点。

背景

easy_refresh已经有一段时间没有更新了,不知道这个问题跟flutter版本有没有关系。

问题点

下拉刷新松开之后,刷新完成,会导致大片头部区域空白,一直不消失。

问题原因

当手势松开之后flutter-sdk里面会调用ScrollPositionwithsinglecontext.goBallistic,导致NestScrollViewgoBallistic无法被通知,如下图。

然后结果就是EasyRefresh的头部指示器已经消失,但是滑动控制器的滑动并没有被触发。

相关代码位置

【计算位置】overExtent of D:\Pub\hosted\pub.flutter-io.cn\easy_refresh-3.4.0\lib\src\notifier\indicator_notifier.dart
【返回结果刷新结果】: _onRefresh of D:\Pub\hosted\pub.flutter-io.cn\easy_refresh-3.4.0\lib\src\easy_refresh.dart
【指示器计算位置】_calculateOffset of D:\Pub\hosted\pub.flutter-io.cn\easy_refresh-3.4.0\lib\src\notifier\indicator_notifier.dart
监听用户滑动到的位置:_onUserOffset of D:\Pub\hosted\pub.flutter-io.cn\easy_refresh-3.4.0\lib\src\notifier\indicator_notifier.dart

解决方案

使用EasyRefresh.builder配合取innerController,复用physics最好。

示例代码

dart 复制代码
class _RoomListContent extends StatefulWidget {
  const _RoomListContent({required this.topPadding});

  final bool topPadding;

  @override
  State<_RoomListContent> createState() => _RoomListContentState();
}

class _RoomListContentState extends State<_RoomListContent> {
  late final ScrollController innerController = PrimaryScrollController.of(context);

  @override
  Widget build(BuildContext context) {
    return EasyRefresh.builder(
      scrollController: innerController,
      onRefresh: () => provider.refresh(),
      onLoad: () => provider.loadMore(),
      childBuilder: (BuildContext context, ScrollPhysics physics) => CustomScrollView(
        controller: innerController,
        physics: physics,
        slivers: <Widget>[
        .....你的具体组件内容
相关推荐
用户69371750013843 小时前
Google 正在“收紧侧加载”:陌生 APK 安装或需等待 24 小时
android·前端
用户69371750013843 小时前
Room 3.0:这次不是升级,是重来
android·前端·google
alexhilton5 小时前
Compose中的ContentScale:终极可视化指南
android·kotlin·android jetpack
Digitally8 小时前
2026 年 8 款安卓数据擦除软件和应用对比
android
杨忆8 小时前
android 11以上 截图工具类
android
粤M温同学8 小时前
Android Studio 中安装 CodeBuddy AI助手
android·ide·android studio
阿拉斯攀登9 小时前
【RK3576 安卓 JNI/NDK 系列 08】RK3576 实战(二):JNI 调用 I2C 驱动读取传感器数据
android·安卓ndk入门·jni方法签名·java调用c++·rk3576底层开发·rk3576 i2c开发
赶路人儿10 小时前
常见的mcp配置
android·adb
符哥200811 小时前
充电桩 WiFi 局域网配网(Android/Kotlin)流程、指令及实例说明文档
android·开发语言·kotlin
没有了遇见12 小时前
Android 项目架构之<用户信息模块>
android