我正在尝试从 Firebase Friestore 读取最后一个条目,如下所示:
这是我的流:
final getLastEmotion = _emotionsDbReference
.orderBy('timeStamp', descending: true)
.limit(1)
.snapshots();
这是我的流生成器:
StreamBuilder(
stream: getLastEmotion,
builder: (BuildContext context,
AsyncSnapshot lastEmotionSnapshot) {
if (lastEmotionSnapshot.data == null)
return CircularProgressIndicator();
if (lastEmotionSnapshot.hasError) {
return new Text(
'Error in receiving snapshot: ${lastEmotionSnapshot.error}');
}
if (!lastEmotionSnapshot.hasData) {
return Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).primaryColor,
),
);
}
final _lastEmotion = lastEmotionSnapshot.data!['emotion'];
return Text('Last emotion: $_lastEmotion');
}),
我收到以下错误:
Class '_JsonQuerySnapshot' has no instance method '[]'.
Receiver: Instance of '_JsonQuerySnapshot'
Tried calling: []("emotion")
有谁知道可能是什么问题?
请帮忙 :)