首页 > 解决方案 > 在 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

标签: flutterdart

解决方案


推荐阅读