Dart FormBuilder Dotted-Style Map To Nested Map

I currently working on a Flutter mobile app project. The project use dynamic & nested field form. Form Builder is simple. Every field is rely on the name. So, i use dotted-style name. With that can transform them to proper Dart Map payload for the Http request.

Situation


Example:

Field for 1st cart item with details and just the 1st detail quantity. So like;

Field Name: cart.0.details.0.quantity
Value: 1

Field Name: cart.0.details.1.quantity
Value: 2

Form Builder will return value

{
    "cart.0.details.0.quantity": 1,
    "cart.0.details.1.quantity": 2
}

Problem


When to make request. We want Nested Map instead.

Example:

{
     "cart': [
        {
            "details": [
                { "quantity": 1 },
                { "quantity": 2 }
            ]
         }
    ]
}

Solution


Comments

Popular Posts