gpt4 book ai didi

flutter - 如何修复错误 "This function has a return type of Column, but doesn' t 以返回语句结尾”

转载 作者:IT王子 更新时间:2023-10-29 07:10:26 25 4
gpt4 key购买 nike

正在开发一个演示聊天应用程序,尝试从 firestore 返回数据。并收到错误。

child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
StreamBuilder<QuerySnapshot>(
stream: _firestore.collection('messagees').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final messages = snapshot.data.documents;
List<Text> messageWidgets = [];
for (var message in messages) {
final messageText = message.data['text'];
final messageSender = message.data['sender'];
final messageWidget =
Text('$messageText from $messageSender');
messageWidgets.add(messageWidget);
}

return Column(
children: messageWidget,
);
}
},
),

我确实有一个返回语句,所以不应该出现这个错误

最佳答案

如果快照没有数据你还没有写返回类型widget

child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
StreamBuilder<QuerySnapshot>(
stream: _firestore.collection('messagees').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final messages = snapshot.data.documents;
List<Text> messageWidgets = [];
for (var message in messages) {
final messageText = message.data['text'];
final messageSender = message.data['sender'];
final messageWidget =
Text('$messageText from $messageSender');
messageWidgets.add(messageWidget);
}

return Column(
children: messageWidget,
);
}else{ // put this else block
return Container(
child: Text('No Data Found'),
),
}
},
),

关于flutter - 如何修复错误 "This function has a return type of Column, but doesn' t 以返回语句结尾”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57707733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com