我想弹出showModalBottomSheet当我点击返回按钮在android手机。这是我的showModalBottomSheet的例子:
showModalBottomSheet(
context: contextt,
useRootNavigator: true,
isScrollControlled: true,
isDismissible: true,
enableDrag: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(mySize.curve_large),
),),
clipBehavior: Clip.antiAliasWithSaveLayer,
builder: (contextt) {
FocusScope.of(contextt).requestFocus(focusNode);
return SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: TextField(
controller: commentTextController,
cursorColor: theme.orange,
textAlignVertical: TextAlignVertical.center,
textAlign: TextAlign.center,
autofocus: true,
focusNode: focusNode,
maxLines: 2,
minLines: 1,
autocorrect: true,
enableInteractiveSelection: true,)); });},
如果我只是使用显示模态底部表后退按钮是工作,但在使用文本输入在它。所以当我点击返回时,表格不会弹出。我在我的示例小部件"TextInput"之前使用WillPopScope
,但它不起作用:
WillPopScope(
onWillPop: () async {
FocusScope.of(contextt).requestFocus(FocusNode());
Navigator.of(contextt).pop();
return false;
},
谁能帮我一下我该怎么做?顺便说一下,当我连续两次点击后退按钮时,showModalBottomSheet弹出。我想一键搞定!
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
child: const Text("Soo"),
onPressed: () {
showModalBottomSheet(
constraints: BoxConstraints.tightFor(
height: 550,
width: MediaQuery.of(context).size.width,
),
context: context,
useRootNavigator: true,
isScrollControlled: true,
isDismissible: true,
enableDrag: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(10),
),
),
clipBehavior: Clip.antiAliasWithSaveLayer,
builder: (contextt) {
FocusScope.of(contextt).requestFocus(focusNode);
return SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: TextField(
controller: commentTextController,
cursorColor: Colors.red,
textAlignVertical: TextAlignVertical.center,
textAlign: TextAlign.center,
autofocus: true,
focusNode: focusNode,
maxLines: 2,
minLines: 1,
autocorrect: true,
enableInteractiveSelection: true,
),
);
},
);
}),
),
);
}