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
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
},
]
}
CodePudding user response:
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);