1

我不知道如何用 API 动态填充数据行。

我还是 Flutter 的初学者,我只需要知道:如何在 Flutter 中使用 API 填充数据行?

我试过list.map了,但它对我不起作用。

class RecentFiles extends StatelessWidget {
    
  @override
  Future getData() async {
    var url = 'https://sdchb.com/index1';
    var response = await http.get(Uri.parse(url));
    var responsebody = jsonDecode(response.body);
    return responsebody;
  }

  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(defaultPadding),
      decoration: BoxDecoration(
        color: secondaryColor,
        borderRadius: const BorderRadius.all(Radius.circular(10)),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "Recent Files",
            style: Theme.of(context).textTheme.subtitle1,
          ),
          SizedBox(
            width: double.infinity,
            child: DataTable(
              horizontalMargin: 0,
              columnSpacing: defaultPadding,
              columns: [
                DataColumn(
                  label: Text("File Name"),
                ),
                DataColumn(
                  label: Text("Date"),
                ),
                DataColumn(
                  label: Text("Size"),
                ),
              ],
              rows: [],
            ),
          ),
        ],
      ),
    );
    ; //end
  }
}
4

0 回答 0