'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!



Solution 1:[1]

Do DocumentSnapshot snap = snapshot.data as DocumentSnapshot;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vladimir Salguero