flutter - 在 null,/flutter (9972) 上调用了方法 '[]':尝试调用:[]("id")
问题描述
需要你的帮助来一起解决这个错误
解决方案是从邮递员那里发布数据,当我打印 value.data 时,我会在地图中获取数据以及我需要的数据,但是当我将其发送到另一个类模型 git 时出现错误,这是代码和错误
首先是data.vlaue
then((value) {
// print(value.toString());
print(value.data);
print(value.data['status']);
print('this is the value');
ShopLoginModel.thisIsJson(value.data);
emit(ShopPostSuccessState());
}).catchError((error) {
emit(ShopPostErrorState(error.toString()));
print(error.toString());
});
2- 必须向其发送 value.data 的类模型
class ShopLoginModel {
bool status;
String message;
UserData data;
ShopLoginModel.thisIsJson(Map<String, dynamic> json) {
status = json['status'];
message = json['message'];
data = json['data'] != null ? UserData.fromJson(json['data']) : null;
}
}
3-最后是错误
I/flutter ( 9972): {status: true, message: تم تسجيل الدخول بنجاح, data: {id: 5508, name: abdelrahman mohamed, email: abdelrahman_1@gmail.com, phone: 011359633, image: https://student.valuxapps.com/storage/uploads/users/Uh0BKroBp5_1635472870.jpeg, points: 0, credit: 0, token: CrNKyEOStSmxArUTWZ9mL5xvvl7geEqQAl3ZhBEl2TMXCEoxW6C5ELUUFbKy43SfLKSWIT}}
I/flutter ( 9972): true
I/flutter ( 9972): this is the value
I/flutter ( 9972): onChange -- ShopLoginCubit, Change { currentState: Instance of 'ShopPostLoadingState', nextState: Instance of 'ShopPostErrorState' }
I/flutter ( 9972): NoSuchMethodError: The method '[]' was called on null.
I/flutter ( 9972): Receiver: null
I/flutter ( 9972): Tried calling: []("id")
需要你的帮助<3
解决方案
推荐阅读
- c++ - 数组程序的 C++ 协助
- javascript - 如何使长 div 自动滚动直到它到达 div 的底部?
- sql - 使用聚合的计算列仅返回 1 或 0
- hibernate - 休眠查询sql,五条记录但返回两条
- python - 是否可以在不使用 Selenium 的情况下使用 Python 抓取无限滚动的网站?
- reactjs - 在服务器端等待来自 React 应用程序的长时间进程
- macos - 无法连接到 docker 镜像端口 MacOS(kafka/kafdrop 等)
- android - 从 android 中的密钥库中检索证书/密钥相关信息
- c++17 - 折叠表达式中自赋值逗号运算符操作数的未定义行为警告
- python - 检查python中的每一行文本