【发布时间】:2026-01-05 13:55:01
【问题描述】:
我正在使用颤振制作一个有人可以评论的页面。该页面由 showModalBottomSheet 显示。但是当键盘显示在前面时,文本字段被键盘隐藏。
flutter doctor output:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14 18A391, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
✗ Android license status unknown.
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.1)
[!] VS Code (version 1.30.0)
[✓] Connected device (1 available)
代码sn-p:
showModalBottomSheet(
context: context,
builder: (BuildContext sheetContext) {
return new Container(
height: 230.0,
padding: const EdgeInsets.all(20.0),
child: ListView(
children: <Widget>[
new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Text(isMainFloor ? "reply author" :"reply"),
new Expanded(
child: new Text(
title,
style: new TextStyle(color: const Color(0xFF63CA6C)),
)),
new InkWell(
child: new Container(
padding:
const EdgeInsets.fromLTRB(10.0, 6.0, 10.0, 6.0),
decoration: new BoxDecoration(
border: new Border.all(
color: const Color(0xFF63CA6C),
width: 1.0,
),
borderRadius: new BorderRadius.all(
new Radius.circular(6.0))),
child: new Text( "send",
style:
new TextStyle(color: const Color(0xFF63CA6C)),
),
),
onTap: () {
sendReply(authorId);
},
)
],
),
new Container(
height: 10.0,
),
new TextFormField(
maxLines: 5,
controller: _inputController,
focusNode: _focusNode,
decoration: new InputDecoration(
hintText: "balabala……",
hintStyle:
new TextStyle(color: const Color(0xFF808080)),
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0)),
)),
),
new Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom)),
],
)
],
),
);
});
}
【问题讨论】:
-
WorkAround 是 - 从
Container中删除height: 230.0,并在填充小部件中包装列表视图 -Padding( padding: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom), child: ListView(....并删除最后一个填充小部件。 -
@anmol.majhail 我试过你的方法。但它只是一点点使用,它只移动了小距离,输入无法完全显示。我猜 BottomSheet 可能是特殊的小部件,不能表现得很好。我尝试了将这些代码包裹在 Scaffod 中,效果很好。
-
@ShengQiu
BottomSheet有 MaxHeight 约束 - 所以不会增加高度
标签: keyboard flutter textfield flutter-layout