Flutter Отсутствуют аргументы типа для универсального метода

Рейтинг: 0Ответов: 1Опубликовано: 19.07.2023

Скажи мне, в чем проблема? Flutter version 3.7.1 on channel stable Dart version 2.19.1

В этой сьроке "item": List<Map<String, dynamic>>.from(item.map((x) => x.toJson()))

подчеркнута красным map - Missing type arguments for generic method 'map'., что не так в этом коде?

BuyCard buyCardFromJson(String str) => BuyCard.fromJson(json.decode(str));

String buyCardToJson(BuyCard data) => json.encode(data.toJson());

class BuyCard {

  BuyCard({
    this.cashierName,
    this.date,
    this.commit,
    this.phone,
    this.type,
    this.charge,
    this.items,
  });

  factory BuyCard.fromJson(Map<String, dynamic> json) => BuyCard(
    cashierName: json["cashierName"],
    date: json["date"],
    commit: json["commit"],
    phone: json["phone"],
    type: json["type"],
    charge: json["charge"],
    items: Items.fromJson(json["items"]),
  );
  final String cashierName;
  final String date;
  final int commit;
  final String phone;
  final int type;
  final int charge;
  final Items items;

  Map<String, dynamic> toJson() => <String, dynamic>{
    "cashierName": cashierName,
    "date": date,
    "commit": commit,
    "phone": phone,
    "type": type,
    "charge": charge,
    "items": items.toJson(),
  };
}


///-----
class Items {

  Items({
    this.item,
  });

  factory Items.fromJson(Map<String, dynamic> json) => Items(
    item: List<Item>.from(json["item"].map((dynamic x) => Item.fromJson(x))),
  );

  final List<Item> item;
  Map<String, dynamic> toJson() => <String, dynamic>{
    "item": List<Map<String, dynamic>>.from(item.map((x) => x.toJson())),
  };
}


///------
class Item {

  Item({
    this.pos,
    this.sku,
    this.qty,
    this.price,
  });

  factory Item.fromJson(Map<String, dynamic> json) => Item(
    pos: json["pos"],
    sku: json["SKU"],
    qty: json["qty"],
    price: json["price"],
  );
  final int pos;
  final String sku;
  final int qty;
  final int price;

  Map<String, dynamic> toJson() => <String, dynamic>{
    "pos": pos,
    "SKU": sku,
    "qty": qty,
    "price": price,
  };
}

Ответы

▲ 0

Решено

было

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

добавил аргумент

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