首先,我们看看目标和实现效果

Flutter 实现类似美团外卖店铺页面滑动效果 - 图1 Flutter 实现类似美团外卖店铺页面滑动效果 - 图2
我这边是把放活动的地方放在了TabBar上方。至于为什么,哈哈,我怕麻烦,因为美团外卖的放活动的组件和下方商品的组件一并点菜评价商家页面的切换而消失,但是这玩意儿又随商品页面的上滑而消失,算上主滑动组件,我们得做让从商品列表组件上的滑动穿透两级,实在是麻烦。所以我便把活动的组件放在了TabBar上方。

然后我们来分析一下页面结构

Flutter 实现类似美团外卖店铺页面滑动效果 - 图3 Flutter 实现类似美团外卖店铺页面滑动效果 - 图4看了前面的动态图片,我们知道,TabBar下方的内容(即结构图中的Body部分)随页面上滑而延伸,内部也包括了滑动组件。看到这种结构,我们自然很容易想到NestedScrollView这个组件。但是直接使用NestedScrollView有一些问题。举个例子,先看例子代码:

  1. Widget build(BuildContext context) {
  2. return Scaffold(
  3. backgroundColor: Colors.white,
  4. body: NestedScrollView(
  5. headerSliverBuilder: (BuildContext context, bool boxIsScrolled) {
  6. return <Widget>[
  7. SliverAppBar(
  8. pinned: true,
  9. title: Text("首页",style: TextStyle(color: Colors.black)),
  10. backgroundColor: Colors.transparent,
  11. bottom: TabBar(
  12. controller: _tabController,
  13. labelColor: Colors.black,
  14. tabs: <Widget>[
  15. Tab(text: "商品"),
  16. Tab(text: "评价"),
  17. Tab(text: "商家"),
  18. ],
  19. ),
  20. )
  21. ];
  22. },
  23. body: Container(
  24. color: Colors.blue,
  25. child: Center(
  26. child: Text("Body部分"),
  27. ),
  28. ),
  29. ),
  30. );
  31. }
  32. 复制代码

Flutter 实现类似美团外卖店铺页面滑动效果 - 图5看代码,我将SliverAppBar的背景设置为透明。当页面上滑的时候,问题出现了,Body部分穿过了SliverAppBar状态栏下方,到达了屏幕顶部。这样的话,做出来的效果肯定不是我们想要的。另外,由于NestedScrollView内部里面只有一个ScrollController(下方代码中的innerController),Body里面的所有列表的ScrollPosition都将会attach到这个ScrollController上,那么就又有问题了,我们的商品页面里面有两个列表,如果共用一个控制器,那么ScrollPosition也使用的同一个,这可不行啊,毕竟列表都不一样,所以因为NestedScrollView内部里面只有一个ScrollController这一点,就决定了我们不能凭借NestedScrollView来实现这个效果。但是,NestedScrollView对我们也不是没有用,它可是为我们提供了关键思路。 为什么说NestedScrollView依然对我们有用呢?因为它的特性呀,Body部分会随页面上滑而延伸,Body部分的底部始终在屏幕的底部。那么这个Body部分的高度是怎么来的?我们去看看NestedScrollView的代码:

  1. List<Widget> _buildSlivers(BuildContext context,
  2. ScrollController innerController, bool bodyIsScrolled) {
  3. return <Widget>[
  4. ...headerSliverBuilder(context, bodyIsScrolled),
  5. SliverFillRemaining(
  6. child: PrimaryScrollController(
  7. controller: innerController,
  8. child: body,
  9. ),
  10. ),
  11. ];
  12. }
  13. 复制代码

NestedScrollViewbody放到了SliverFillRemaining中,而这SliverFillRemaining的的确确是NestedScrollViewbody能够填满在前方组件于NestedScrollView底部之间的关键。好的,知道了这家伙的存在,我们可以试试自己来做一个跟NestedScrollView有些类似的效果了。我选择了最外层滑动组件CustomScrollView,嘿嘿,NestedScrollView也是继承至CustomScrollView来实现的。

实现一个 NestedScrollView 类似的效果

首先我们写一个跟NestedScrollView结构类似的界面ShopPage出来,关键代码如下:

  1. class _ShopPageState extends State<ShopPage>{
  2. @override
  3. Widget build(BuildContext context) {
  4. return Scaffold(
  5. body: CustomScrollView(
  6. controller: _pageScrollController,
  7. physics: ClampingScrollPhysics(),
  8. slivers: <Widget>[
  9. SliverAppBar(
  10. pinned: true,
  11. title: Text("店铺首页", style: TextStyle(color: Colors.white)),
  12. backgroundColor: Colors.blue,
  13. expandedHeight: 300),
  14. SliverFillRemaining(
  15. child: ListView.builder(
  16. controller: _childScrollController,
  17. padding: EdgeInsets.all(0),
  18. physics: ClampingScrollPhysics(),
  19. shrinkWrap: true,
  20. itemExtent: 100.0,
  21. itemCount: 30,
  22. itemBuilder: (context, index) => Container(
  23. padding: EdgeInsets.symmetric(horizontal: 1),
  24. child: Material(
  25. elevation: 4.0,
  26. borderRadius: BorderRadius.circular(5.0),
  27. color:
  28. index % 2 == 0 ? Colors.cyan : Colors.deepOrange,
  29. child: Center(child: Text(index.toString())),
  30. ))))
  31. ],
  32. ),
  33. );
  34. }
  35. }
  36. 页面结构 滑动效果
  37. 复制代码

Flutter 实现类似美团外卖店铺页面滑动效果 - 图6 Flutter 实现类似美团外卖店铺页面滑动效果 - 图7由动图可以看到,滑动下面的ListView不能带动CustomScrollView中的SliverAppBar伸缩。我们应该怎么实现呢?首先想想我们要的效果:

  • 向上滑动ListView时,如果SliverAppBar是展开状态,应该先让SliverAppBar收缩,当SliverAppBar不能收缩时,ListView才会滚动。
  • 向下滑动ListView时,当ListView已经滑动到第一个不能再滑动时,SliverAppBar应该展开,直到SliverAppBar完全展开。

SliverAppBar应不应该响应,响应的话是展开还是收缩。我们肯定需要根据滑动方向CustomScrollView与ListView已滑动距离来判断。所以我们需要一个工具来根据滑动事件是谁发起的、CustomScrollView与ListView的状态、滑动的方向、滑动的距离、滑动的速度等进行协调它们怎么响应。
至于这个协调器怎么写,我们先不着急。我们应该搞清楚 滑动组件原理,推荐文章:
从零开始实现一个嵌套滑动的PageView(一)
从零开始实现一个嵌套滑动的PageView(二)
从零开始实现一个嵌套滑动的PageView(三)
Flutter的滚动以及sliver约束
看了这几个文章,结合我们的使用场景,我们需要明白:

  • 当手指在屏幕上滑动时,ScrollerPosition中的applyUserOffset方法会得到滑动矢量;
  • 当手指离开屏幕时, ScrollerPosition中的goBallistic方法会得到手指离开屏幕前滑动速度;
  • 至始自终,主滑动组件上发起的滑动事件,对子滑动部件无干扰,那么我们在协调时,只需要把子部件的事件传给协调器分析、协调。

简单来说,我们需要修改 ScrollerPosition, ScrollerController。修改ScrollerPosition是为了把手指滑动距离手指离开屏幕前滑动速度传递给协调器协调处理。修改ScrollerController是为了保证滑动控制器在创建ScrollerPosition创建的是我们修改过后的ScrollerPosition。那么,开始吧!

实现子部件上下滑动关联主部件

首先,假设我们的协调器类名为ShopScrollCoordinator

滑动控制器 ShopScrollerController

我们去复制ScrollerController的源码,然后为了方便区分,我们把类名改为ShopScrollController。 控制器需要修改的部分如下:

  1. class ShopScrollController extends ScrollController {
  2. final ShopScrollCoordinator coordinator;
  3. ShopScrollController(
  4. this.coordinator, {
  5. double initialScrollOffset = 0.0,
  6. this.keepScrollOffset = true,
  7. this.debugLabel,
  8. }) : assert(initialScrollOffset != null),
  9. assert(keepScrollOffset != null),
  10. _initialScrollOffset = initialScrollOffset;
  11. ScrollPosition createScrollPosition(ScrollPhysics physics,
  12. ScrollContext context, ScrollPosition oldPosition) {
  13. return ShopScrollPosition(
  14. coordinator: coordinator,
  15. physics: physics,
  16. context: context,
  17. initialPixels: initialScrollOffset,
  18. keepScrollOffset: keepScrollOffset,
  19. oldPosition: oldPosition,
  20. debugLabel: debugLabel,
  21. );
  22. }
  23. ///其他的代码不要动
  24. }
  25. 复制代码

滑动滚动位置 ShopScrollPosition

原版的ScrollerController创建的ScrollPositionScrollPositionWithSingleContext。 我们去复制ScrollPositionWithSingleContext的源码,然后为了方便区分,我们把类名改为ShopScrollPosition。前面说了,我们主要是需要修改applyUserOffset,goBallistic两个方法。

  1. class ShopScrollPosition extends ScrollPosition
  2. implements ScrollActivityDelegate {
  3. final ShopScrollCoordinator coordinator; // 协调器
  4. ShopScrollPosition(
  5. {@required this.coordinator,
  6. @required ScrollPhysics physics,
  7. @required ScrollContext context,
  8. double initialPixels = 0.0,
  9. bool keepScrollOffset = true,
  10. ScrollPosition oldPosition,
  11. String debugLabel})
  12. : super(
  13. physics: physics,
  14. context: context,
  15. keepScrollOffset: keepScrollOffset,
  16. oldPosition: oldPosition,
  17. debugLabel: debugLabel,
  18. ) {
  19. if (pixels == null && initialPixels != null) correctPixels(initialPixels);
  20. if (activity == null) goIdle();
  21. assert(activity != null);
  22. }
  23. /// 当手指滑动时,该方法会获取到滑动距离
  24. /// [delta]滑动距离,正增量表示下滑,负增量向上滑
  25. /// 我们需要把子部件的 滑动数据 交给协调器处理,主部件无干扰
  26. @override
  27. void applyUserOffset(double delta) {
  28. ScrollDirection userScrollDirection =
  29. delta > 0.0 ? ScrollDirection.forward : ScrollDirection.reverse;
  30. if (debugLabel != coordinator.pageLabel)
  31. return coordinator.applyUserOffset(delta, userScrollDirection, this);
  32. updateUserScrollDirection(userScrollDirection);
  33. setPixels(pixels - physics.applyPhysicsToUserOffset(this, delta));
  34. }
  35. /// 以特定的速度开始一个物理驱动的模拟,该模拟确定[pixels]位置。
  36. /// 此方法遵从[ScrollPhysics.createBallisticSimulation],该方法通常在当前位置超出
  37. /// 范围时提供滑动模拟,而在当前位置超出范围但具有非零速度时提供摩擦模拟。
  38. /// 速度应以每秒逻辑像素为单位。
  39. /// [velocity]手指离开屏幕前滑动速度,正表示下滑,负向上滑
  40. @override
  41. void goBallistic(double velocity, [bool fromCoordinator = false]) {
  42. if (debugLabel != coordinator.pageLabel) {
  43. // 子部件滑动向上模拟滚动时才会关联主部件
  44. if (velocity > 0.0) coordinator.goBallistic(velocity);
  45. } else {
  46. if (fromCoordinator && velocity <= 0.0) return;
  47. }
  48. assert(pixels != null);
  49. final Simulation simulation =
  50. physics.createBallisticSimulation(this, velocity);
  51. if (simulation != null) {
  52. beginActivity(BallisticScrollActivity(this, simulation, context.vsync));
  53. } else {
  54. goIdle();
  55. }
  56. }
  57. /// 返回未使用的增量。
  58. /// 从[NestedScrollView]的自定义[ScrollPosition][_NestedScrollPosition]拷贝
  59. double applyClampedDragUpdate(double delta) {
  60. assert(delta != 0.0);
  61. final double min =
  62. delta < 0.0 ? -double.infinity : math.min(minScrollExtent, pixels);
  63. final double max =
  64. delta > 0.0 ? double.infinity : math.max(maxScrollExtent, pixels);
  65. final double oldPixels = pixels;
  66. final double newPixels = (pixels - delta).clamp(min, max) as double;
  67. final double clampedDelta = newPixels - pixels;
  68. if (clampedDelta == 0.0) return delta;
  69. final double overScroll = physics.applyBoundaryConditions(this, newPixels);
  70. final double actualNewPixels = newPixels - overScroll;
  71. final double offset = actualNewPixels - oldPixels;
  72. if (offset != 0.0) {
  73. forcePixels(actualNewPixels);
  74. didUpdateScrollPositionBy(offset);
  75. }
  76. return delta + offset;
  77. }
  78. /// 返回过度滚动。
  79. /// 从[NestedScrollView]的自定义[ScrollPosition][_NestedScrollPosition]拷贝
  80. double applyFullDragUpdate(double delta) {
  81. assert(delta != 0.0);
  82. final double oldPixels = pixels;
  83. // Apply friction: 施加摩擦:
  84. final double newPixels =
  85. pixels - physics.applyPhysicsToUserOffset(this, delta);
  86. if (oldPixels == newPixels) return 0.0;
  87. // Check for overScroll: 检查过度滚动:
  88. final double overScroll = physics.applyBoundaryConditions(this, newPixels);
  89. final double actualNewPixels = newPixels - overScroll;
  90. if (actualNewPixels != oldPixels) {
  91. forcePixels(actualNewPixels);
  92. didUpdateScrollPositionBy(actualNewPixels - oldPixels);
  93. }
  94. return overScroll;
  95. }
  96. }
  97. 复制代码

滑动协调器 ShopScrollCoordinator

  1. class ShopScrollCoordinator {
  2. /// 页面主滑动组件标识
  3. final String pageLabel = "page";
  4. /// 获取主页面滑动控制器
  5. ShopScrollController pageScrollController([double initialOffset = 0.0]) {
  6. assert(initialOffset != null, initialOffset >= 0.0);
  7. _pageInitialOffset = initialOffset;
  8. _pageScrollController = ShopScrollController(this,
  9. debugLabel: pageLabel, initialScrollOffset: initialOffset);
  10. return _pageScrollController;
  11. }
  12. /// 创建并获取一个子滑动控制器
  13. ShopScrollController newChildScrollController([String debugLabel]) =>
  14. ShopScrollController(this, debugLabel: debugLabel);
  15. /// 子部件滑动数据协调
  16. /// [delta]滑动距离
  17. /// [userScrollDirection]用户滑动方向
  18. /// [position]被滑动的子部件的位置信息
  19. void applyUserOffset(double delta,
  20. [ScrollDirection userScrollDirection, ShopScrollPosition position]) {
  21. if (userScrollDirection == ScrollDirection.reverse) {
  22. /// 当用户滑动方向是向上滑动
  23. updateUserScrollDirection(_pageScrollPosition, userScrollDirection);
  24. final innerDelta = _pageScrollPosition.applyClampedDragUpdate(delta);
  25. if (innerDelta != 0.0) {
  26. updateUserScrollDirection(position, userScrollDirection);
  27. position.applyFullDragUpdate(innerDelta);
  28. }
  29. } else {
  30. /// 当用户滑动方向是向下滑动
  31. updateUserScrollDirection(position, userScrollDirection);
  32. final outerDelta = position.applyClampedDragUpdate(delta);
  33. if (outerDelta != 0.0) {
  34. updateUserScrollDirection(_pageScrollPosition, userScrollDirection);
  35. _pageScrollPosition.applyFullDragUpdate(outerDelta);
  36. }
  37. }
  38. }
  39. }
  40. 复制代码

现在,我们在_ShopPageState里添加代码:

  1. class _ShopPageState extends State<ShopPage>{
  2. // 页面滑动协调器
  3. ShopScrollCoordinator _shopCoordinator;
  4. // 页面主滑动部件控制器
  5. ShopScrollController _pageScrollController;
  6. // 页面子滑动部件控制器
  7. ShopScrollController _childScrollController;
  8. /// build 方法中的CustomScrollView和ListView 记得加上控制器!!!!
  9. @override
  10. void initState() {
  11. super.initState();
  12. _shopCoordinator = ShopScrollCoordinator();
  13. _pageScrollController = _shopCoordinator.pageScrollController();
  14. _childScrollController = _shopCoordinator.newChildScrollController();
  15. }
  16. @override
  17. void dispose() {
  18. _pageScrollController?.dispose();
  19. _childScrollController?.dispose();
  20. super.dispose();
  21. }
  22. }
  23. 复制代码

这个时候,基本实现了实现子部件上下滑动关联主部件。效果如图:
Flutter 实现类似美团外卖店铺页面滑动效果 - 图8

实现美团外卖 点菜 页面的Body结构

修改_ShopPageStateSliverFillRemaining中内容:

  1. /// 注意添加一个新的控制器!!
  2. SliverFillRemaining(
  3. child: Row(
  4. children: <Widget>[
  5. Expanded(
  6. child: ListView.builder(
  7. controller: _childScrollController,
  8. padding: EdgeInsets.all(0),
  9. physics: ClampingScrollPhysics(),
  10. shrinkWrap: true,
  11. itemExtent: 50,
  12. itemCount: 30,
  13. itemBuilder: (context, index) => Container(
  14. padding: EdgeInsets.symmetric(horizontal: 1),
  15. child: Material(
  16. elevation: 4.0,
  17. borderRadius: BorderRadius.circular(5.0),
  18. color: index % 2 == 0
  19. ? Colors.cyan
  20. : Colors.deepOrange,
  21. child: Center(child: Text(index.toString())),
  22. )))),
  23. Expanded(
  24. flex: 4,
  25. child: ListView.builder(
  26. controller: _childScrollController1,
  27. padding: EdgeInsets.all(0),
  28. physics: ClampingScrollPhysics(),
  29. shrinkWrap: true,
  30. itemExtent: 150,
  31. itemCount: 30,
  32. itemBuilder: (context, index) => Container(
  33. padding: EdgeInsets.symmetric(horizontal: 1),
  34. child: Material(
  35. elevation: 4.0,
  36. borderRadius: BorderRadius.circular(5.0),
  37. color: index % 2 == 0
  38. ? Colors.cyan
  39. : Colors.deepOrange,
  40. child: Center(child: Text(index.toString())),
  41. ))))
  42. ],
  43. ))
  44. 复制代码

看效果
Flutter 实现类似美团外卖店铺页面滑动效果 - 图9看来还有些问题,什么问题呢?当我只上滑右边的子部件,当SliverAppBar的最小化时,我们可以看到左边的子部件的第一个居然不是0。如图:Flutter 实现类似美团外卖店铺页面滑动效果 - 图10跟前面的NestedScrollView中的问题一样。那我们怎么解决呢?改呗!灵感来自于,Flutter Candies 一桶天下协调器添加方法:

  1. /// 获取body前吸顶组件高度
  2. double Function() pinnedHeaderSliverHeightBuilder;
  3. bool applyContentDimensions(double minScrollExtent, double maxScrollExtent,
  4. ShopScrollPosition position) {
  5. if (pinnedHeaderSliverHeightBuilder != null) {
  6. maxScrollExtent = maxScrollExtent - pinnedHeaderSliverHeightBuilder();
  7. maxScrollExtent = math.max(0.0, maxScrollExtent);
  8. }
  9. return position.applyContentDimensions(
  10. minScrollExtent, maxScrollExtent, true);
  11. }
  12. 复制代码

修改ShopScrollPositionapplyContentDimensions方法:

  1. @override
  2. bool applyContentDimensions(double minScrollExtent, double maxScrollExtent,
  3. [bool fromCoordinator = false]) {
  4. if (debugLabel == coordinator.pageLabel && !fromCoordinator)
  5. return coordinator.applyContentDimensions(
  6. minScrollExtent, maxScrollExtent, this);
  7. return super.applyContentDimensions(minScrollExtent, maxScrollExtent);
  8. }
  9. 复制代码

这个时候,我们只需要在页面的初始化协调器后,给协调器赋值一个返回body之前的所有锁顶组件折叠后的高度之和的函数就可以了。

实现美团外卖 店铺页面 头部全屏化展开显示店铺信息效果

目标如图:
image.svg为什么说是全屏化,这个相信不需要我多讲,展开的卡片周围的灰色就是个padding而已。 用过SliverAppBar的人基本上都能想到,将它的expandedHeight设置成屏幕高度就可以实现头部在展开的时候填充满整个屏幕。但是,页面中SliverAppBar默认并不是完全展开状态,当然也不是完全收缩状态,完全收缩状态的话,这玩意儿就只剩个AppBar在顶部了。那么我们应该怎么让它默认显示成类似美团那样的呢? 还记得我们的ScrollController的构造函数有个名称为initialScrollOffset可传参数吧,嘿嘿,只要我们把页面主滑动部件的控制器设置了initialScrollOffset,页面岂不是就会默认定在initialScrollOffset对应的位置。 好的,默认位置可以了。可是,从动图可以看到,当我们下拉部件,使默认位置 < 主部件已下滑距离 < 最大展开高度并松开手指时,SliverAppBar会继续展开至最大展开高度。那么我们肯定要捕捉手指离开屏幕事件。这个时候呢,我们可以使用Listener组件包裹CustomScrollView,然后在ListeneronPointerUp中获取手指离开屏幕事件。好的,思路有了。我们来看看怎么实现吧:
协调器外部添加枚举:

  1. enum PageExpandState { NotExpand, Expanding, Expanded }
  2. 复制代码

协调器添加代码:

  1. /// 主页面滑动部件默认位置
  2. double _pageInitialOffset;
  3. /// 获取主页面滑动控制器
  4. ShopScrollController pageScrollController([double initialOffset = 0.0]) {
  5. assert(initialOffset != null, initialOffset >= 0.0);
  6. _pageInitialOffset = initialOffset;
  7. _pageScrollController = ShopScrollController(this,
  8. debugLabel: pageLabel, initialScrollOffset: initialOffset);
  9. return _pageScrollController;
  10. }
  11. /// 当默认位置不为0时,主部件已下拉距离超过默认位置,但超过的距离不大于该值时,
  12. /// 若手指离开屏幕,主部件头部会回弹至默认位置
  13. double _scrollRedundancy = 80;
  14. /// 当前页面Header最大程度展开状态
  15. PageExpandState pageExpand = PageExpandState.NotExpand;
  16. /// 当手指离开屏幕
  17. void onPointerUp(PointerUpEvent event) {
  18. final double _pagePixels = _pageScrollPosition.pixels;
  19. if (0.0 < _pagePixels && _pagePixels < _pageInitialOffset) {
  20. if (pageExpand == PageExpand.NotExpand &&
  21. _pageInitialOffset - _pagePixels > _scrollRedundancy) {
  22. _pageScrollPosition
  23. .animateTo(0.0,
  24. duration: const Duration(milliseconds: 400), curve: Curves.ease)
  25. .then((value) => pageExpand = PageExpand.Expanded);
  26. } else {
  27. pageExpand = PageExpand.Expanding;
  28. _pageScrollPosition
  29. .animateTo(_pageInitialOffset,
  30. duration: const Duration(milliseconds: 400), curve: Curves.ease)
  31. .then((value) => pageExpand = PageExpand.NotExpand);
  32. }
  33. }
  34. }
  35. 复制代码

这个时候,我们把协调器的onPointerUp方法传给ListeneronPointerUp,我们基本实现了想要的效果。 But,经过测试,其实它还有个小问题,有时候手指松开它并不会按照我们想象的那样自动展开或者回到默认位置。问题是什么呢?我们知道,手指滑动列表然后离开屏幕时,ScrollPositiongoBallistic方法会被调用,所以onPointerUp刚被调用立马goBallistic也被调用,当goBallistic传入的速度绝对值很小的时候,那么列表的模拟滑动距离就很小很小,甚至为0.0。那么结果是怎么样的,自然而然出现在脑袋中了吧。
我们还需要继续修改一下ShopScrollPositiongoBallistic方法:

  1. @override
  2. void goBallistic(double velocity, [bool fromCoordinator = false]) {
  3. if (debugLabel != coordinator.pageLabel) {
  4. if (velocity > 0.0) coordinator.goBallistic(velocity);
  5. } else {
  6. if (fromCoordinator && velocity <= 0.0) return;
  7. if (coordinator.pageExpand == PageExpandState.Expanding) return;
  8. }
  9. assert(pixels != null);
  10. final Simulation simulation =
  11. physics.createBallisticSimulation(this, velocity);
  12. if (simulation != null) {
  13. beginActivity(BallisticScrollActivity(this, simulation, context.vsync));
  14. } else {
  15. goIdle();
  16. }
  17. }
  18. 复制代码

记得页面initState中,初始化_pageScrollController的时候,记得传入默认位置的值。 此时需要注意一下,默认位置的值并不是页面在默认状态下SliverAppBar底部在距屏幕顶部的距离,而是屏幕高度减去其底部距屏幕顶部的距离,即initialOffset = screenHeight - x,而这个x我们根据设计或者自己的感觉来设置便是。这里我取200。 来来来,我们看看效果怎么样!!
Flutter 实现类似美团外卖店铺页面滑动效果 - 图12
文章项目案例 github链接 flutter_meituan_shop

作者:CyJay
链接:https://juejin.im/post/5e3f73b4e51d4526d1209005
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。