Streambuilder - flutter 迁移后出错 - 快照语法
Streambuilder - error after flutter migration - snapshot syntax
我在迁移之前使用了这段代码
StreamBuilder(
stream: FirebaseDatabase.instance
.ref()
.child('user')
.child(_userID)
.onValue,
builder: (context, snapshot) {
if (snapshot.hasData) {
_networkImageUrl = snapshot.data.snapshot.value["img"];
return Text(_networkImageUrl.toString());
} else {
return Container();
}
}),
在“dart pub upgrade --null-safety”之后出现错误:
The property 'snapshot' can't be unconditionally accessed because the receiver can be 'null'.
我试着用“!”修复它但它不起作用,它保持相同的错误
这是代码的工作原理:
StreamBuilder<DatabaseEvent>(
stream: FirebaseDatabase.instance
.ref()
.child('user')
.child(_userID)
.onValue,
builder: (BuildContext context,AsyncSnapshot snapshot) {
if (snapshot.hasData) {
Map<dynamic, dynamic> userDocument = snapshot.data.snapshot.value;
_networkImageUrl = userDocument["img"]
return Text(_networkImageUrl.toString());
} else {
return Container();
}
}),
thx 2 h8moss
我在迁移之前使用了这段代码
StreamBuilder(
stream: FirebaseDatabase.instance
.ref()
.child('user')
.child(_userID)
.onValue,
builder: (context, snapshot) {
if (snapshot.hasData) {
_networkImageUrl = snapshot.data.snapshot.value["img"];
return Text(_networkImageUrl.toString());
} else {
return Container();
}
}),
在“dart pub upgrade --null-safety”之后出现错误:
The property 'snapshot' can't be unconditionally accessed because the receiver can be 'null'.
我试着用“!”修复它但它不起作用,它保持相同的错误
这是代码的工作原理:
StreamBuilder<DatabaseEvent>(
stream: FirebaseDatabase.instance
.ref()
.child('user')
.child(_userID)
.onValue,
builder: (BuildContext context,AsyncSnapshot snapshot) {
if (snapshot.hasData) {
Map<dynamic, dynamic> userDocument = snapshot.data.snapshot.value;
_networkImageUrl = userDocument["img"]
return Text(_networkImageUrl.toString());
} else {
return Container();
}
}),
thx 2 h8moss