簡體   English   中英

如何從api獲取此數據並將其顯示在數據表顫動中

[英]How can I fetch this data from api and display it in data table flutter

[
[
"id",
"date",
"title",
"pries",
"total",
"note"
],
[
"",
"",
"revolving balance",
0,
0,
""
],
[
"5555",
"2021-08-28",
"text",
100,
-200,
""
],
]

如何從 api 獲取此數據並將其顯示在數據表 flutter 中,我想獲取此數據並將其顯示在表中,我嘗試了很多但無濟於事,如果有人可以提供幫助

要從 api 獲取數據,您可以查看此從互聯網獲取數據

要顯示您的數據,您可以使用DataTable Widget

注意下面代碼的使用

DataTable(
  columns: const <DataColumn>[
    DataColumn(
      label: Text(
        'Name',
        style: TextStyle(fontStyle: FontStyle.italic),
      ),
    ),
    DataColumn(
      label: Text(
        'Age',
        style: TextStyle(fontStyle: FontStyle.italic),
      ),
    ),
    DataColumn(
      label: Text(
        'Role',
        style: TextStyle(fontStyle: FontStyle.italic),
      ),
    ),
  ],
  rows: const <DataRow>[
    DataRow(
      cells: <DataCell>[
        DataCell(Text('Sarah')),
        DataCell(Text('19')),
        DataCell(Text('Student')),
      ],
    ),
    DataRow(
      cells: <DataCell>[
        DataCell(Text('Janine')),
        DataCell(Text('43')),
        DataCell(Text('Professor')),
      ],
    ),
    DataRow(
      cells: <DataCell>[
        DataCell(Text('William')),
        DataCell(Text('27')),
        DataCell(Text('Associate Professor')),
      ],
    ),
  ],
);

對於您顯示的數據,api 數據中的第一個數組似乎是表列的標題,下一個數組是這些列的內容。

您要做的第一件事是將第一個數組數據輸入到列屬性中。 然后,在行屬性中輸入下一個數組數據

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM