【问题标题】:How to add row element dynamically by calling API in flutter?如何通过在flutter中调用API动态添加行元素?
【发布时间】:2021-11-07 02:34:24
【问题描述】:

**我的问题是我想通过调用我的 API 继续在我的行中添加数据,而不是更新它**

 SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: DataTable(
          columnSpacing: 13.0,
          columns: <DataColumn>[
            DataColumn(label: Text("TestName")),
            DataColumn(label: Text("Fee")),
            DataColumn(label: Text("Discounted Fee")),
            DataColumn(label: Text("Booking Fee")),
          ],
         rows: <DataRow>[
          DataRow(
             cells: <DataCell>[
            DataCell(Container(child: Text(testName?? '',overflow: TextOverflow.ellipsis))),
            DataCell(Text(getTestFeeObj?.fee ?? '')),
            DataCell(Text(getTestFeeObj?.discountedFee ?? '')),
            DataCell(Text(getTestFeeObj?.bookingFee ?? '')),
           ],
          )
         ]
         ),
      )

【问题讨论】:

  • 使用提供异步数据加载序列的 dart 流。

标签: json flutter api dart


【解决方案1】:

您可以在数组中收集您的 API 数据,向其中添加新数据并使用 map 函数以这种方式构造您的 DataRow

// your array data
var datas = [...]

// add new data to it
setState((){
  datas.add(...);
});

// use them for your DataRow
DataTable(
  row: datas.map((data){
    return DataRow(
       cells:[
         // your cells
         DataCell(Text(data.fieldValue))
       ]
    );
  }).toList()
)
 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    相关资源
    最近更新 更多