Flutter之DraggableScrollableSheet可滑动sheet实现类似抖音商品详情页

Flutter之DraggableScrollableSheet可滑动sheet实现类似抖音商品详情页

介绍:

使用DraggableScrollableSheet可实现类似抖音视频上商品弹出页的滑动动效果。以下代码是嵌入我的子页面。

代码如下:
  • 父页面(showModalBottomSheet)
    如果要实现上滑满屏的效果,需要将scrollController传入到子页面
   showModalBottomSheet(
      isScrollControlled: true,
      context: context,
      builder: (context) {
        return StatefulBuilder(
          builder: (context1, setState2) {
            return DraggableScrollableSheet(
              expand: false,
               //初始化占用父容器高度
              initialChildSize: 0.75,
               //占用父组件的最小高度
              minChildSize: 0.75,
              builder: (BuildContext context, ScrollController scrollController) {
                return ClipRRect(
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(ScreenAdapter.setHeight(14)),
                    topRight: Radius.circular(ScreenAdapter.setHeight(14)),
                  ),
                  //嵌入我的子页面(ProductDetailsPage),如果要实现上滑满屏的效果,需要将scrollController传入到子页面
                  child: ProductDetailsPage(arguments: {
                    "id": item['id'],
                    // 传入controller,实现上滑效果
                    'controller': scrollController
                  }),
                );
              },
            );
          },
        );
      },
    )
  • 子页面(ProductDetailsPage)
    将子页面可滑动组件的controller设置为父页面传入的controller,便可以实现上滑满屏的效果
 Scaffold(
      backgroundColor: Color.fromRGBO(238, 238, 238, 1),
      body: Stack(
        children: [
          _productInfo.isNotEmpty
              ? CustomScrollView(
                 //将子页面可滑动组件的controller设置为父页面传入的controller
                  controller: _controller,
                  slivers: [
                    _stickBanner(),
                    _buildStickyBar(),
                    _buildList(),
                  ],
                )
              : LoadingView(results: _results, page: 'productDetails'),
          //底部收藏,比价,客服,加入购物车,立即购买
          _bottomOpration(),
          MyCommonWidget.shopCartEntry(context, _count),
        ],
      ),
    )
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yuwenwenwenwenyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值