我希望有人可以解释为什么在显式调用Firestore.instance.collection('data').snapshots()与调用包含Firestore.instance.collection('data').snapshots( )并返回一个流。
调用包含Firestore.instance.collection('data').snapshots()的方法仅在对 firestore 数据进行更改后抓取数据快照。
class GlobalAppModel extends Model{
......//other global data elements
Stream getDataStreamSnapshots(){
Firestore.instance.collection('data').snapshots();
}
}
class DataDetailWidget2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
dataStream = AppModel.of(context);
....
body: Container(
child: StreamBuilder(
stream: Firestore.instance.collection('data').snapshots(), //This works great.
//stream: dataStream.getDataStreamSnapshots(), //This does not grab a snapshot until firestore is updated.
builder: (context, snapshot) {
.....
}
....
}
}