Flutter中如何移除WoltModalSheet的顶部区域?
移除WoltModalSheet顶部区域的实现方法
要去掉WoltModalSheet的顶部区域,直接调整这两个关键参数就行:
- 关闭拖拽手柄显示:把原代码里的
showDragHandle: true改成showDragHandle: false,这会直接隐藏顶部的拖拽条。 - 移除页面默认顶部栏:在
WoltModalSheetPage里添加topBar: null,彻底去掉页面自带的顶部区域;如果还有顶部间隙,再加个pagePadding: EdgeInsets.zero消除内边距。
修改后的完整代码如下:
WoltModalSheet.show( context: context, pageListBuilder: (context) { return [ WoltModalSheetPage( topBar: null, // 移除页面默认顶部栏 pagePadding: EdgeInsets.zero, // 消除页面内边距(可选,根据需求调整) child: Container( color: Color.fromARGB(255, 3, 5, 24), height: context.width + 100, width: context.width, ), ), ]; }, pageIndexNotifier: ValueNotifier(0), onModalDismissedWithBarrierTap: null, onModalDismissedWithDrag: null, decorator: null, modalTypeBuilder: (BuildContext context) { final width = MediaQuery.sizeOf(context).width; if (width < 523) { return WoltModalType.bottomSheet(); } else if (width < 800) { return WoltModalType.dialog(); } else { return WoltModalType.sideSheet(); } }, transitionAnimationController: null, enableDrag: false, showDragHandle: false, // 隐藏拖拽手柄 useSafeArea: false, );
简单说下逻辑:
showDragHandle: false:关掉顶部那个拖拽小条topBar: null:WoltModalSheetPage默认会有顶部栏区域,设为null就直接移除了pagePadding: EdgeInsets.zero:如果你的页面内容和顶部还有空隙,加这个就能把默认的内边距清掉
内容的提问来源于stack exchange,提问作者chichi
相关产品推荐
相关产品推荐

