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

背景

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

问题点

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

问题原因

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

然后结果就是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>[
        .....你的具体组件内容
相关推荐
_祝你今天愉快33 分钟前
Android 高级绘制:[五] 贝塞尔曲线与计算规则
android
FungLeo15 小时前
FengCMS · PHP+MySQL 升级实录 · 危险默认值之殇:root/123456、认证码 8888 写进配置加载器
android·mysql·php·安全加固·fengcms
yz_aiks15 小时前
Termux 使用教程:把安卓手机变成随身 Linux(装 Python、SSH 远程、跑自动化脚本)
android·linux·python·智能手机·ssh·termux
booboosui1 天前
编号没变,消息还是来了:Mac 端通知读取漏第二条的原因
android
雨白2 天前
单例设计模式:从 Java/Kotlin 实现到 Android 实战
android
hai_android2 天前
一行 asLiveData,背后是一座生命周期的桥
android·java·kotlin
阿杰m2 天前
Android源码第二十三章:Telephony、RIL 与 IMS——来电怎么到应用?
android
booboosui2 天前
没人认领 .md:安卓把报告交给了音乐播放器打开
android
用户60709759149062 天前
AOSP 14 OTA 升级指导(四):update_engine 内部机制——Action 流水线与写盘
android
恋猫de小郭2 天前
Jetpack Compose 1.13 发布,憋了这么久终有交代了
android·前端·flutter