0

I am trying to integrate this add stock feature into the app,but i am kind of stuck how do pass those incremented items data to http package,i have made view and shows data just like this

please checkout entire code for this process

https://github.com/Abhijithsp/flutter-image_upload/blob/master/Add%20Stocks.dart

Process

How do i pass the data just like this

{
    "id"        : "", //NOT NULL IF EDIT
    "station_id": 2,
    "name"      : "Test Stocks",
    "unit"      : "1", (DROPDOWN) ==>1 UNITS
    "branches"  : [{
        "branch_id": 87, 
        "kg"       : 10,
        "gm"       : 5,
        "ltr"      : 0,
        "ml"       : 0,
        "counter"  : 0
    },{
        "branch_id": 88, 
        "kg"       : 10,
        "gm"       : 8,
        "ltr"      : 0,
        "ml"       : 0,
        "counter"  : 0
    },
  ]
}

1 Answer 1

1

You can use list_branch_details along with its StockBranchDetailsModel store inside it for every rows. and whenever any change in data the you can save to particular position of that list named list_branch_details and while sending data

var data ={};
var branches=[];
var branch ={};

data["name"] = "Test Stocks";
data["unit"] = "1";

for(int i =0;i< list_branch_details.length; i++ ) {
    branch = {};
    branch["branch_id"] = list_branch_details.get(i).getBranchId();
    branch["kg"] = list_branch_details.get(i).getKg();
    branches.add(branch);
}

data["branches"] = branches;

and just encode it.

jsonEncode(data);
Sign up to request clarification or add additional context in comments.

1 Comment

it worked 🤗🤗@Hardik Mehta

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.