我有 Flutter/Firebase 应用程序,它允许用户将他们的图书阅读数据存储到 Firestore(已完成阅读的图书、当前阅读等)。我想实现一个功能,它允许用户查看是否有人完成阅读一本书(FS 卷对象字段“completedUsers”更新)或有人开始阅读新书(FS 帐户对象字段“nowReading”更新)。
我想我应该使用 CollectionReference().snapshots().listen() - 方法,但我还没有弄清楚如何以及如何使用 StreamBuilder 进行设置,所以我可以获得关于哪一部分 db 的确切信息对象已更新。
这是我关于用户帐户和数量的模型:
@JsonSerializable(explicitToJson: true)
class Account {
String name;
String uid;
List<Volume> nowReading;
List<Volume> wantToRead;
List<Account> friends;
Map<String, Volume> tips;
Account(
{this.name,
this.uid,
this.nowReading,
this.wantToRead,
this.friends,
this.tips});
factory Account.fromJson(Map<String, dynamic> json) =>
_$AccountFromJson(json);
Map<String, dynamic> toJson() => _$AccountToJson(this);
}
@JsonSerializable(explicitToJson: true)
class Volume {
String id;
String title;
String description;
String smallThumbnail;
String bigThumbnail;
List<String> authors;
List<String> categories;
int published;
int pageCount;
double averageGoogleRating;
double averageUserRating;
List<UserReview> userReviews;
List<String> completedUsers;
Volume(
{this.id,
this.title,
this.description,
this.smallThumbnail,
this.bigThumbnail,
this.authors,
this.categories,
this.published,
this.pageCount,
this.averageGoogleRating,
this.averageUserRating,
this.userReviews,
this.completedUsers});
factory Volume.fromJson(Map<String, dynamic> json) => _$VolumeFromJson(json);
Map<String, dynamic> toJson() => _$VolumeToJson(this);
}