Ошибка прикрытия объекта в кодируемый объект Ошибка в реализации пользовательского объекта flutter dart graphql - PullRequest
0 голосов
/ 01 апреля 2020
String createOrder = """
  mutation createOrder(\$userId: String!, \$warehouseId: String!, \$productMapping: [OrderProductCreateInput!]!){
  createOrder(createInput:{
    userId: \$userId
    warehouseId: \$warehouseId
    products: \$productMapping
    options: {
      autoConfirm: true
    }
  }){
    id
    warehouseId
    products{
      product{
        id
      }
    }
  }
}

  """;

Выше приведен манипулирующий запрос, и я передаю данные как

List<OrderProductCreateInput> orderFun() {
    for (CartItem ca in _cartItems) {
      Map<String, dynamic> jsonBuilder = {
        "count": ca.quantity,
        "productId": ca.product.id
      };
      print(jsonBuilder.values);
      OrderProductCreateInput opcInput =
          OrderProductCreateInput.fromJson(jsonBuilder);
      _opcList.add(opcInput);
      print("THE LENGTH OF OPCINPUT IS ${_opcList.length}");
    }
    return _opcList;
  }

class OrderProductCreateInput {
  int count;
  String productId;

  OrderProductCreateInput.fromJson(Map json)
      : count = json['count'],
        productId = json['productId'];

}

Поэтому, когда пользователь нажимает кнопку «Заказ», я передаю cart.orderFun в качестве параметра

* 1006. *

я видел ответ на Flutter / GraphQL - мутация с пользовательским типом в качестве параметра , но не совсем понял

Появляется следующая ошибка

I/flutter (25262): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (25262): The following JsonUnsupportedObjectError was thrown while handling a gesture:
I/flutter (25262): Converting object to an encodable object failed: Instance of 'OrderProductCreateInput'
I/flutter (25262):
I/flutter (25262): When the exception was thrown, this was the stack:
I/flutter (25262): #0      _JsonStringifier.writeObject  (dart:convert/json.dart:649:7)
I/flutter (25262): #1      _JsonStringifier.writeList  (dart:convert/json.dart:697:7)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...