[英]flutter method called null
I am trying to display a badge to show my uses that they have an unread message but I keep getting this error The method '[]' was called on null. Receiver: null Tried calling: []("recieverId") The relevant error-causing widget
我正在尝试显示一个徽章以显示我的用户有未读消息,但我不断收到此错误
The method '[]' was called on null. Receiver: null Tried calling: []("recieverId") The relevant error-causing widget
The method '[]' was called on null. Receiver: null Tried calling: []("recieverId") The relevant error-causing widget
here is my code这是我的代码
class ViewLayout extends StatelessWidget {
final User contact;
final ChatMethods _chatMethods = ChatMethods();
ViewLayout({
@required this.contact,
});
bool isread;
Map<dynamic, dynamic> chatlist;
@override
Widget build(BuildContext context) {
final UserProvider userProvider = Provider.of<UserProvider>(context);
FirebaseUser user;
if (chatlist['recieverId'] == user.uid) {
isread = true;
} else {
isread = chatlist['isread'] == null ? true : chatlist['isread'];
}
convo class康沃 class
class Convo {
Convo({this.chatlist});
factory Convo.fromFireStore(DocumentSnapshot doc) {
final Map<String, dynamic> data = doc.data;
return Convo(chatlist: data['chatlist'] ?? <dynamic>{});
}
Map<dynamic, dynamic> chatlist;
}
Add null check before using chatlist, because your chatlist is null.在使用聊天列表之前添加 null 检查,因为您的聊天列表是 null。
if(chatlist !=null){
if (chatlist['recieverId'] == user.uid) {
isread = true;
} else {
isread = chatlist['isread'] == null ? true : chatlist['isread'];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.