Flutter 列表<;动态>';不是类型为';地图<;字符串,动态>;

Flutter 列表<;动态>';不是类型为';地图<;字符串,动态>;,flutter,Flutter,我在颤振中时间不长。“List”不是“Map”类型的子类型。 这显然是一个解码问题,您正在等待一个列表,但是一个对象到达了,我建议您在这个应用程序中支持自己对类进行建模。() 类传输响应{ 转移反应({ 这是senderUser, 这个.recipientUser, }); 最终名单发送者; 最终用户列表; 工厂TransferResponse.fromJson(映射json)=>TransferResponse( senderUser:List.from(json[“sender_user”]

我在颤振中时间不长。
“List”不是“Map”类型的子类型。


这显然是一个解码问题,您正在等待一个列表,但是一个对象到达了,我建议您在这个应用程序中支持自己对类进行建模。()

类传输响应{
转移反应({
这是senderUser,
这个.recipientUser,
});
最终名单发送者;
最终用户列表;
工厂TransferResponse.fromJson(映射json)=>TransferResponse(
senderUser:List.from(json[“sender_user”].map((x)=>user.fromJson(x)),
recipientUser:List.from(json[“recipient_user”].map((x)=>user.fromJson(x)),
);
映射到JSON()=>{
“sender_user”:List.from(senderUser.map((x)=>x.toJson()),
“recipient_user”:List.from(recipientUser.map((x)=>x.toJson()),
};
}
类用户{
使用者({
这个身份证,
这个.recipientUser,
这是senderUser,
这个硬币,
这个,比尔,
这个,身份,,
这个.createdAt,
这个.updatedAt,
});
最终int id;
最终int接收方用户;
最终int发送器;
最终整型硬币;
最后的串票据;
最终国际地位;
最终日期时间创建日期;
最终日期时间更新日期;
工厂用户.fromJson(映射json)=>User(
id:json[“id”],
接收方用户:json[“接收方用户”],
senderUser:json[“发件人\用户”],
硬币:json[“硬币”],
法案:json[“法案”],
状态:json[“状态”],
createdAt:DateTime.parse(json[“created_at”]),
updatedAt:DateTime.parse(json[“updated_at”]),
);
映射到JSON()=>{
“id”:id,
“接收方用户”:接收方用户,
“发送方\用户”:发送方用户,
“硬币”:硬币,
“法案”:法案,
“地位”:地位,
“created_at”:createdAt.toiso8601字符串(),
“updated_at”:updatedAt.toIso8601String(),
};
}
 Future<TransferResponse> getTransfers(String apiToken) async {
    try {
      Response response = await _dio.get(
        apiEndpoint + "packages",
        options: Options(headers: {"Authorization": apiToken}),
      );
 
      return TransferResponse.fromJson(response.data);//'List<dynamic>' is not a subtype of type 'Map<String, dynamic>'
    } catch (error, stacktrace) {
      return null;
    }
  }


class TransferResponse {
  List<SenderUser> senderUser;
  List<RecipientUser> recipientUser;

  TransferResponse({this.senderUser, this.recipientUser});

  TransferResponse.fromJson(Map<String, dynamic> json) {
    if (json['sender_user'] != null) {
      senderUser = new List<SenderUser>();
      json['sender_user'].forEach((v) {
        senderUser.add(new SenderUser.fromJson(v));
      });
    }
    if (json['recipient_user'] != null) {
      recipientUser = new List<RecipientUser>();
      json['recipient_user'].forEach((v) {
        recipientUser.add(new RecipientUser.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.senderUser != null) {
      data['sender_user'] = this.senderUser.map((v) => v.toJson()).toList();
    }
    if (this.recipientUser != null) {
      data['recipient_user'] =
          this.recipientUser.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class SenderUser {
  int id;
  int recipientUser;
  int senderUser;
  int coin;
  String bill;
  int status;
  String createdAt;
  String updatedAt;

  SenderUser(
      {this.id,
        this.recipientUser,
        this.senderUser,
        this.coin,
        this.bill,
        this.status,
        this.createdAt,
        this.updatedAt});

  SenderUser.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    recipientUser = json['recipient_user'];
    senderUser = json['sender_user'];
    coin = json['coin'];
    bill = json['bill'];
    status = json['status'];
    createdAt = json['created_at'];
    updatedAt = json['updated_at'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['recipient_user'] = this.recipientUser;
    data['sender_user'] = this.senderUser;
    data['coin'] = this.coin;
    data['bill'] = this.bill;
    data['status'] = this.status;
    data['created_at'] = this.createdAt;
    data['updated_at'] = this.updatedAt;
    return data;
  }
}

class RecipientUser {
  int id;
  int recipientUser;
  int senderUser;
  int coin;
  String bill;
  int status;
  String createdAt;
  String updatedAt;

  RecipientUser(
      {this.id,
        this.recipientUser,
        this.senderUser,
        this.coin,
        this.bill,
        this.status,
        this.createdAt,
        this.updatedAt});

  RecipientUser.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    recipientUser = json['recipient_user'];
    senderUser = json['sender_user'];
    coin = json['coin'];
    bill = json['bill'];
    status = json['status'];
    createdAt = json['created_at'];
    updatedAt = json['updated_at'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['recipient_user'] = this.recipientUser;
    data['sender_user'] = this.senderUser;
    data['coin'] = this.coin;
    data['bill'] = this.bill;
    data['status'] = this.status;
    data['created_at'] = this.createdAt;
    data['updated_at'] = this.updatedAt;
    return data;
  }
}
{
   "sender_user": [
       {
           "id": 43,
           "recipient_user": 149,
           "sender_user": 201,
           "coin": 1,
           "bill": "3P8FkW4pi2GTR1EXCq7CfAfCkVaSCfPytwR",
           "status": 8,
           "created_at": "2021-03-20 16:30:02",
           "updated_at": "2021-03-20 16:30:02"
       }
   ],
   "recipient_user": [
       {
           "id": 44,
           "recipient_user": 201,
           "sender_user": 26,
           "coin": 2,
           "bill": "3P84TFr91wrtveMXimfCY1BeNAVzhAvmf3o",
           "status": 8,
           "created_at": "2021-03-20 16:32:48",
           "updated_at": "2021-03-20 16:32:48"
       }
   ]
}
class TransferResponse {
    TransferResponse({
        this.senderUser,
        this.recipientUser,
    });

    final List<User> senderUser;
    final List<User> recipientUser;

    factory TransferResponse.fromJson(Map<String, dynamic> json) => TransferResponse(
        senderUser: List<User>.from(json["sender_user"].map((x) => User.fromJson(x))),
        recipientUser: List<User>.from(json["recipient_user"].map((x) => User.fromJson(x))),
    );

    Map<String, dynamic> toJson() => {
        "sender_user": List<dynamic>.from(senderUser.map((x) => x.toJson())),
        "recipient_user": List<dynamic>.from(recipientUser.map((x) => x.toJson())),
    };
}

class User {
    User({
        this.id,
        this.recipientUser,
        this.senderUser,
        this.coin,
        this.bill,
        this.status,
        this.createdAt,
        this.updatedAt,
    });

    final int id;
    final int recipientUser;
    final int senderUser;
    final int coin;
    final String bill;
    final int status;
    final DateTime createdAt;
    final DateTime updatedAt;

    factory User.fromJson(Map<String, dynamic> json) => User(
        id: json["id"],
        recipientUser: json["recipient_user"],
        senderUser: json["sender_user"],
        coin: json["coin"],
        bill: json["bill"],
        status: json["status"],
        createdAt: DateTime.parse(json["created_at"]),
        updatedAt: DateTime.parse(json["updated_at"]),
    );

    Map<String, dynamic> toJson() => {
        "id": id,
        "recipient_user": recipientUser,
        "sender_user": senderUser,
        "coin": coin,
        "bill": bill,
        "status": status,
        "created_at": createdAt.toIso8601String(),
        "updated_at": updatedAt.toIso8601String(),
    };
}