小编Zap*_*Zap的帖子

如何使用PrimaryScrollController从NestedScrollView内部的CustomScrollView获取偏移量

我有NestedScrollView一个SliverAppBar。的身体NestedScrollView是有一个小部件CustomScrollViewSliverList

我想从ScrollController给予的偏移量,NestedScrollView但是它只给我偏移量,直到看不见为止SliverAppBar,但是此后,SliverList继续滚动但ScrollController没有给出偏移量。

NestedScrollView(
  headerSliverBuilder: (_, __) => SliverAppBar(..),
  body: RefreshIndicator(
    child: CustomScrollView(..),
  ),
)
Run Code Online (Sandbox Code Playgroud)

CustomScrollView会自动使用PrimaryScrollController提供NestedScrollView
当侦听器附加到该滚动视图时,当SliverAppBar幻灯片滑入和滑出视图时,将调用该侦听器,直到position.extentAfter等于0.0,然后再也不会更新,无论您向下滚动多远,因为extentAfter始终保持在0.0

如何获取CustomScrollView内部的滚动位置NestedScrollView


实作

之所以重要,PrimaryScrollController是因为ScrollController应当具有的功能PrimaryScrollController。无论如何,为了SliverAppBar使它起作用(即,它与内容一起滚动出视图),该NestedScrollView controller参数需要以某种方式与CustomScrollView controller(或primary)参数匹配。

这是一个演示

任何允许内容滚动的实现都可以PrimaryScrollController.of(context)。 …

flutter flutter-layout

7
推荐指数
1
解决办法
322
查看次数

标签 统计

flutter ×1

flutter-layout ×1