FutureBuilder<DocumentSnapshot> The getter 'isEmpty' was called on null

Viewed 61

I didnt change anything but it gives me this error. I tried something for solve but I couldn.

My Error

The following NoSuchMethodError was thrown building FutureBuilder(dirty, state: _FutureBuilderState#02733): The getter 'isEmpty' was called on null. Receiver: null Tried calling: isEmpty

My code where I get Error

 class _ProfileScreenState extends State<ProfileScreen> {
      @override
      Widget build(BuildContext context) {
        var screenHeight = MediaQuery.of(context).size.height;
        var screenWidth = MediaQuery.of(context).size.width;
        return Scaffold(
            backgroundColor: Colors.white,
            body: FutureBuilder(
                future: usersRef.doc(widget.visitedUserId).get(),
                builder: (BuildContext context, AsyncSnapshot snapshot) {
                  if (!snapshot.hasData) {
                    return Center(
                      child: CircularProgressIndicator(
                        valueColor: AlwaysStoppedAnimation(LogiColor),
                      ),
                    );
                  }
                  UserModel userModel = UserModel.fromDoc(snapshot.data);
                  return ListView(... }));
      }
    }

My UserModel

 import 'package:cloud_firestore/cloud_firestore.dart';

class UserModel {
  String id;
  String name;
  String profilePicture;
  String email;
  List interests;
  String reportsTo;
  String badges;
  String attendeEvents;
  String city;
  String phoneNumber;
  String position;
  String department;
  String coverImage;

  UserModel(
      {this.id,
      this.name,
      this.profilePicture,
      this.email,
      this.interests,
      this.reportsTo,
      this.badges,
      this.attendeEvents,
      this.city,
      this.phoneNumber,
      this.position,
      this.department,
      this.coverImage,});

  factory UserModel.fromDoc(DocumentSnapshot doc) {
    return UserModel(
  id: doc.id,
  name: doc.data()['name'],
  profilePicture: doc.data()['profilePicture'],
  email: doc.data()['email'],
  interests: doc.data()['interests'],
  reportsTo: doc.data()['repdoc.data()ortsTo'],
  badges: doc.data()['badges'],
  attendeEvents: doc.data()['attendeEvents'],
  city: doc.data()['city'],
  phoneNumber: doc.data()['phoneNumber'],
  position: doc.data()['position'],
  department: doc.data()['department'],
  coverImage: doc.data()['coverImage'],
);
  }
}
1 Answers

I recommend to you, in these cases, to use the debugger tool, it helps a lot in these "null" cases. (that are 90% of the times, our fault hehe)

Related