如何BottomSheet在 Flutter 中以编程方式关闭 Persistent ?还有没有办法只显示持久底部工作表的一部分,用户可以向上拖动工作表以查看完整内容?
下面的代码是显示持久化的底表。
homeScaffoldKey.currentState.showBottomSheet<Null>((BuildContext context) {
return Container(
height: 300.0,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.all(16.0),
child: Text(
'Persistent header for bottom bar!',
textAlign: TextAlign.left,
)),
Text(
'Then here there will likely be some other content '
'which will be displayed within the bottom bar',
textAlign: TextAlign.left,
),
],
));
});
Run Code Online (Sandbox Code Playgroud)
您可以使用关闭底部工作表
Navigator.of(context).pop();
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用PersistentBottomSheetController关闭底部工作表。这是你将如何做到的。
PersistentBottomSheetController _controller; // instance variable
Run Code Online (Sandbox Code Playgroud)
以下可以放在onPressed()将显示底部工作表的事件类型中。
_controller = homeScaffoldKey
.currentState
.showBottomSheet((BuildContext context) {
return YourWidgetImplementation();
},
);
Run Code Online (Sandbox Code Playgroud)
你可以使用关闭它
_controller.close();
Run Code Online (Sandbox Code Playgroud)
还有没有办法只显示持久底部工作表的一部分,用户可以向上拖动工作表以查看完整内容?
抱歉,您必须自己完成,目前 Flutter 中还没有这样的内置功能。您可以用GestureDetector自己的方式操纵事物。
你可以使用这个答案