这可能是一个非常容易解决的问题,但我想我还是在这里问它:有什么方法可以将小部件锚定在一个CustomScrollView
? 我想使用CustomScrollView
来支持应用栏中的灵活空间,但我需要将输入小部件固定在屏幕底部。我尝试使用给定的小部件将其嵌套CustomScrollView
到 aColumn
中,但它似乎不起作用:
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
CustomScrollView(
slivers: <Widget>[
_buildAppBar(), // Returns a SliverAppBar
_buildMessages(), // Returns a StreamBuilder that returns a SliverList
],
),
MessageInputWidget(), // Input that needs to stay fixed
],
);
}
这是 _buildMessages() 方法:
Widget _buildMessages(BuildContext context) {
return StreamBuilder<List<Message>>(
stream: widget.classroom.messages(),
builder: (context, snapshot) {
print('[DEBUG] Building chat with updated message stream...');
if (!snapshot.hasData || snapshot.data == null) {
return Center(
child: CircularProgressIndicator(),
);
}
_messages = snapshot.data;
print('[DEBUG] Building ${_messages.length} messages...');
return SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
if (index == _messages.length) {
return _buildHeader(context);
}
return MessageWidget(
message: _messages[index],
isReceived: _user.id != _messages[index].sentBy.id,
showUser: (index ==
0) || // Show _avatar if it's the first msg
(index >=
1 && // Or if it's a different _user than the last
!(_messages[index].sentBy.id ==
_messages[index - 1].sentBy.id)),
);
},
childCount: _messages.length,
),
);
});
}
有什么建议么?我找到了一些示例,但它们构建了整体CustomScrollView
,而我只想在SliverList
获得新快照时构建。有什么建议么?