带有文本字段的 Flutter floatingActionButton 没有完全位于键盘上方。需要像 facebook messanger 这样的东西
Flutter floatingActionButton with textfield is not fully above keyboard. Need something like facebook messanger
我有一个奇怪的问题,我不知道如何解决。我用 TextField 创建了一个自定义的 floatingActionButton,并将 floatingActionButtonLocation 设置为 FloatingActionButtonLocation.centerDocked。但是,当文本字段展开时,它会进入键盘下方。谁能帮我解决这个问题吗?
Widget build(BuildContext context) {
return Scaffold(
appBar: GameDetailAppBar(
widget.model.selectedGame.name,
widget.model.selectedGame.currentUserMetadata['isOwner'],
widget.model),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: showGamePageBottomBar
? GamePageBottomBar(widget.model)
: _buildCommentBox(),
backgroundColor: Colors.white,
body: Container(
child: _buildGamePage(),
),
);
}
Widget _buildCommentBox() {
return Container(
margin: EdgeInsets.only(bottom: 55),
width: screenWidth(context),
color: Colors.white,
child: Container(
margin: EdgeInsets.only(top: 5, bottom: 5, right: 27, left: 27),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
border: Border.all(
color: createColor('#FFBF00'),
),
),
child: Padding(
padding: const EdgeInsets.only(left: 11, right: 11),
child: new TextFormField(
controller: _commentController,
// focusNode: commentFocusNode,
maxLines: 5,
minLines: 1,
decoration: new InputDecoration(
border: InputBorder.none,
suffix: Text(
'Post',
style: WidgetUtils.me.getLatoMedium(
16,
createColor('#0DB630'),
),
),
),
),
),
),
);
}
_buildCommentBox 中的边距应该以某种方式基于 _commentController 行是动态的。即使文本字段有 1 行,容器的边距部分也会在键盘下方。
这是我的 floatingActionButton 没有文本时的样子:
需要修复多行文本时的这种行为(您看不到键盘下方的底部边框):
这就是我想要的:
你应该看看这两种方法(我会 link 回答我发现的可能有助于你解决这个问题的问题):
在您的 Scaffold
小工具中使用 resizeToAvoidBottomPadding: true
()
或
使用
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom));
在您的 Padding
小部件上
()
最佳解决方案,也适用于滚动视图:
脚手架 -> bottomSheet
Scaffold(
bottomSheet: WIDGET,
)
我有一个奇怪的问题,我不知道如何解决。我用 TextField 创建了一个自定义的 floatingActionButton,并将 floatingActionButtonLocation 设置为 FloatingActionButtonLocation.centerDocked。但是,当文本字段展开时,它会进入键盘下方。谁能帮我解决这个问题吗?
Widget build(BuildContext context) {
return Scaffold(
appBar: GameDetailAppBar(
widget.model.selectedGame.name,
widget.model.selectedGame.currentUserMetadata['isOwner'],
widget.model),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: showGamePageBottomBar
? GamePageBottomBar(widget.model)
: _buildCommentBox(),
backgroundColor: Colors.white,
body: Container(
child: _buildGamePage(),
),
);
}
Widget _buildCommentBox() {
return Container(
margin: EdgeInsets.only(bottom: 55),
width: screenWidth(context),
color: Colors.white,
child: Container(
margin: EdgeInsets.only(top: 5, bottom: 5, right: 27, left: 27),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
border: Border.all(
color: createColor('#FFBF00'),
),
),
child: Padding(
padding: const EdgeInsets.only(left: 11, right: 11),
child: new TextFormField(
controller: _commentController,
// focusNode: commentFocusNode,
maxLines: 5,
minLines: 1,
decoration: new InputDecoration(
border: InputBorder.none,
suffix: Text(
'Post',
style: WidgetUtils.me.getLatoMedium(
16,
createColor('#0DB630'),
),
),
),
),
),
),
);
}
_buildCommentBox 中的边距应该以某种方式基于 _commentController 行是动态的。即使文本字段有 1 行,容器的边距部分也会在键盘下方。
这是我的 floatingActionButton 没有文本时的样子:
需要修复多行文本时的这种行为(您看不到键盘下方的底部边框):
这就是我想要的:
你应该看看这两种方法(我会 link 回答我发现的可能有助于你解决这个问题的问题):
在您的 Scaffold
小工具中使用 resizeToAvoidBottomPadding: true
(
或
使用
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom));
在您的 Padding
小部件上
(
最佳解决方案,也适用于滚动视图:
脚手架 -> bottomSheet
Scaffold(
bottomSheet: WIDGET,
)