问题描述
我在 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:
我的愿望不是弹跳,而是开始被拖累。
解决方法
在我看来,您可以使用滚动控制器在到达顶部时关闭底部表单
if (_controller.offset <= _controller.position.minScrollExtent &&
!_controller.position.outOfRange) {
.....
.....
);
}
您可以在 Listview 中使用 shrinkWrap=true
阻止列表从顶部跳出。
要关闭底部表格,您可以参考 this stackoverflow post
我还没有尝试过这段代码,但希望它能以某种方式帮助你。
另外,我认为如果你保持现在的样子,在“X”的右侧顶部插入一个小“-”,用户可以触摸它向下滑动,它看起来会很好。