I have the below code in my profile page. The code is working absolutely fine in android ,but on web when I open my profile page it is showing
unexpected null value error ,
The code which is pointing to error in debug console :
return Container(
child: StreamBuilder<DocumentSnapshot>(
stream: FirebaseFirestore.instance
.collection('users')
.doc(profileId)
.snapshots(),
builder: (context,snapshot) {
if (!snapshot.hasData) {
return Container(
alignment: FractionalOffset.center,
child: CircularProgressIndicator());
}
User user = User.fromDocument(snapshot.data!);
return Scaffold(
//all body widgets
);
the debug console shows
The following TypeErrorImpl was thrown building StreamBuilder<DocumentSnapshot<Object?>>(dirty, state: _StreamBuilderBaseState<DocumentSnapshot<Object?>, AsyncSnapshot<DocumentSnapshot<Object?>>>#556d2):
Unexpected null value.
The relevant error-causing widget was
StreamBuilder<DocumentSnapshot<Object?>>
lib/profile_page.dart:615
CodePudding user response:
I think you should put this line User user = User.fromDocument(snapshot.data!);
into else
, like this:
if (!snapshot.hasData) { // if snapshot has no data this is going to run
return Container(
alignment: FractionalOffset.center,
child: CircularProgressIndicator());
}
else{ // if snapshot has data this is going to run
User user = User.fromDocument(snapshot.data!);
}
CodePudding user response:
Check Firebase permissions for the web