When I use this code:
return FutureBuilder(
future: searchResultsFuture,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return cargandoCircular();
}
List<UserResult> searchResults = [];
snapshot.data.docs.forEach((doc) {
User user = User.fromDocument(doc);
UserResult searchResult = UserResult(user);
searchResults.add(searchResult);
});
return ListView(
children: searchResults,
);
I get the error:
The property 'docs' can't be unconditionally accessed because the receiver can be 'null'.
Try making the access conditional (using '?.') or adding a null check to the target ('!').
Adding the null check doesn't solve anything, also everything is declared in a User
class on another dart file, like this:
class User {
final String id;
final String username;
final String email;
final String photoUrl;
final String displayName;
final String bio;
User(
{required this.id,
required this.username,
required this.email,
required this.photoUrl,
required this.displayName,
required this.bio});
factory User.fromDocument(DocumentSnapshot doc) {
return User(
id: doc['id'],
email: doc['email'],
username: doc['username'],
photoUrl: doc['photoUrl'],
displayName: doc['displayName'],
bio: doc['bio'],
);}}