将 json 数组传递给 http flutter

Pass json array to http flutter

我正在尝试将这个添加库存功能集成到应用程序中,但我有点卡住如何将这些增加的项目数据传递给 http 包,我已经像这样查看和显示数据

请检查此过程的完整代码

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

进程

如何像这样传递数据

{
    "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
    },
  ]
}

您可以对每一行使用 list_branch_details 及其内部的 StockBranchDetailsModel 存储。每当数据发生任何变化时,您都可以保存到名为 list_branch_details 的列表的特定位置,同时发送数据

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;

并对其进行编码。

jsonEncode(data);