我有一个聊天页面,其中有一个列表来显示消息。我想在键盘出现和发送新邮件时滚动到末尾。我该怎么解决?下面是我的代码:
Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: const Icon(Icons.arrow_back)),
elevation: 0,
centerTitle: true,
title: Text(
widget.chatName!,
overflow: TextOverflow.ellipsis,
)),
body: Column(children: [
Expanded(
child: ListView.separated(
shrinkWrap: true,
controller: _controller,
physics: const BouncingScrollPhysics(),
itemBuilder: (context, index) {
return Column(children: [
SingleChatBubble(
user: widget.user,
message:
messageState.message[index])
]);
},
separatorBuilder: (context, index) =>
const SizedBox(height: 5.0),
itemCount: messageState.message.length),
),
_messageSection(chatState.chat, otherUser)
])));
1条答案
按热度按时间cngwdvgl1#
我的方法是首先指定一个
FocusNode
并将其分配给消息发送方TextField
。我会调整聊天室的initState
方法:这样,当您点击
TextField
时,无论您在哪里,消息都会在底部滚动。我使用的整个示例代码: