登录
推荐 文章 Go 技术 课程 下载 专题 AI
首页 >  文章 >  软件教程

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

时间:2026-08-20 23:53:32 445浏览 收藏

背景

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

问题点

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

问题原因

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

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

相关代码位置

【计算位置】overExtent of D:Pubhostedpub.flutter-io.cneasy_refresh-3.4.0libsrcnotifierindicator_notifier.dart

【返回结果刷新结果】: _onRefresh of D:Pubhostedpub.flutter-io.cneasy_refresh-3.4.0libsrceasy_refresh.dart

【指示器计算位置】D:\Pub\hosted\pub.flutter-io.cn\easy_refresh-3.4.0\lib\src\notifier\indicator_notifier.dart文件中的_calculateOffset

监听用户滑动位置:D:Pubhostedpub.flutter-io.cneasy_refresh-3.4.0libsrcnotifierindicator_notifier.dart中的_onUserOffset

解决方案

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

示例代码

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: [
        .....你的具体组件内容
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>