微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我的 modalBottomSheet 只能在边缘上拖动

如何解决我的 modalBottomSheet 只能在边缘上拖动

我在 DraggableScrollableSheet 构建器中有一个 showModalBottomSheet。我已经为模态表设置了 isdismissible: true,但我的小部件只能在边缘上拖动。那是因为我在 ListView 中有一个 DraggableScrollableSheet

当列表在拖动开始时过度滚动时我应该做什么?

这是我的代码

 showModalBottomSheet<void>(
      context: context,isScrollControlled: true,isdismissible: true,backgroundColor: Colors.transparent,enableDrag: true,builder: (BuildContext context) {
        return StackedSheet(
          backgroundColor: backgroundColor,onBackgroundColor: onBackgroundColor,padding: padding,minChildSize: minChildSize,maxChildSize: maxChildSize,onClose: onClose,child: SafeArea(
            top: false,child: child,),);
      },);

StackedSheet 在哪里:

LayoutBuilder(
        builder: (context,constraints) {
          return DraggableScrollableSheet(
            key: Key('$_childSize'),initialChildSize: min(_childSize,widget.maxChildSize),minChildSize:
                min(_childSize - _childSize * 0.2,widget.minChildSize),maxChildSize: min(_childSize,expand: false,builder: (
              BuildContext context,ScrollController scrollController,) {
              return ListView.separated( ...blah blah)
           }

这是一个 GIF:

Here is a GIF:

我的愿望不是弹跳,而是开始被拖累。

解决方法

在我看来,您可以使用滚动控制器在到达顶部时关闭底部表单

if (_controller.offset <= _controller.position.minScrollExtent &&
            !_controller.position.outOfRange) {
           .....
           ..... 
         );
       }

您可以在 Listview 中使用 shrinkWrap=true 阻止列表从顶部跳出。 要关闭底部表格,您可以参考 this stackoverflow post

我还没有尝试过这段代码,但希望它能以某种方式帮助你。

另外,我认为如果你保持现在的样子,在“X”的右侧顶部插入一个小“-”,用户可以触摸它向下滑动,它看起来会很好。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。