在Flutter中是否可以防止关闭抽屉?
我正在web应用中使用 endDrawer
作为表单。 我已经禁用了滑动打开,同时我也只想允许通过按钮关闭它,这样用户就不会因为点击外部而意外关闭它。 然而,我没有看到任何如prevent dismiss这样的布尔值或任何实现 WillPopScope
的方式。
那么 - 是否可以在不创建自己的 Drawer
实现的情况下实现这一点?
在Flutter中是否可以防止关闭抽屉?
我正在web应用中使用 endDrawer
作为表单。 我已经禁用了滑动打开,同时我也只想允许通过按钮关闭它,这样用户就不会因为点击外部而意外关闭它。 然而,我没有看到任何如prevent dismiss这样的布尔值或任何实现 WillPopScope
的方式。
那么 - 是否可以在不创建自己的 Drawer
实现的情况下实现这一点?
我有同样的问题,不想让用户在滑动或在抽屉外部单击时意外关闭包含表单的抽屉。
我的解决方案是将抽屉的内容包装在一个GestureDetector中,然后添加:
onHorizontalDragEnd: (v) {
// do nothing
},
return Scaffold(
endDrawerEnableOpenDragGesture: false,
endDrawer: Container(
width: MediaQuery.of(context).size.width,
child: Drawer(
backgroundColor: Colors.transparent,
child: GestureDetector(
onHorizontalDragEnd: (v) {
// do nothing
},
child: Row(
children: [
Expanded(child: Container(color: Colors.transparent,)),
Container(
/// replace by your desired width
width: MediaQuery.of(context).size.width/2,
color: Colors.white,
child: Center(child: Text("your content")),
),
],
),
),
),
),
body: Center(child: Text("your boby")),
);
class FullScreenPage extends StatelessWidget {
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: Text("Big screen web app")),
body: Row(
children: [
Drawer(/* Menu items here */),
Placeholder(/* Normal body here */),
]
)
);
}