1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] How can I add a support of for Custom Types within Objectbox?

Discussão em 'Mobile' iniciado por Stack, Novembro 7, 2024 às 10:52.

  1. Stack

    Stack Membro Participativo

    How can I add a support of for Custom Types within Objectbox?

    Example:

    class ShopListData {
    int id;
    int amount;
    bool done;
    ProductData productData;

    ShopListData(
    {required this.id,
    required this.amount,
    required this.done,
    required this.productData});
    }

    class ProductData {
    String? name;
    String? brand;
    String? ingredients;
    String? quantity;

    ProductData({
    this.name,
    this.brand,
    this.ingredients,
    this.quantity,
    });
    }


    Where I get the error:


    cannot use the default constructor of 'ShopListData': don't know how to initialize param productData - no such property.

    I found out that one possible solution is to use relations, but since I have always 1:1 relation I think I don't need that option.

    Instead I would like to store data as defined by ShopListData Class within the database. I read the custom type documentation. However I don't understand what is needed to add support/converter for the ProductData type. Who has an idea and could provide an example of how to add such support/converter?

    Continue reading...

Compartilhe esta Página