简体   繁体   中英

Flutter DocumentSnapshot - Error: A value of type 'Object?' can't be assigned to a variable of type 'DocumentSnapshot'

return StreamBuilder(
  stream: usersRef.doc(post.userId).snapshots(),
  builder: (context, snapshot) {
    if (snapshot.hasData) {
      DocumentSnapshot snap = snapshot.data;
      UserModel user = UserModel.fromJson(snap.data()!);

Hello, all. The 'snapshot.data' is giving me the above error, Please, help! Thanks!

Do DocumentSnapshot snap = snapshot.data as DocumentSnapshot;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM