You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Flutter ListView中展示MariaDB获取的Device全部属性

解决方案

你可以通过以下几种方式在ListView中展示Device的所有属性:

方法1:利用ListTile的title和subtitle拆分展示

ListTile自带主标题(title)和副标题(subtitle),可以将不同属性分配到这两个区域,布局简洁清晰:

return ListTile(
  title: Text('ID: ${dList[index].iD} | 类型: ${dList[index].type}'),
  subtitle: Text('位置: ${dList[index].location}'),
  textColor: Colors.white,
);

方法2:自定义多行布局(用Column组合文本)

如果需要给不同属性设置差异化样式(比如加粗、调整间距),可以在ListTile的title中嵌套Column组件:

return ListTile(
  title: Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      Text('ID: ${dList[index].iD}', style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
      const SizedBox(height: 4),
      Text('位置: ${dList[index].location}'),
      Text('类型: ${dList[index].type}'),
    ],
  ),
  textColor: Colors.white,
);

方法3:直接拼接所有属性为单行/多行文本

如果不需要复杂排版,直接用换行符拼接所有属性,简单直接:

return ListTile(
  title: Text(
    'ID: ${dList[index].iD}\n位置: ${dList[index].location}\n类型: ${dList[index].type}',
    style: const TextStyle(color: Colors.white, fontSize: 16),
  ),
);

将上述任意一种代码替换你原itemBuilder中的返回语句即可,根据你的UI需求选择合适的实现方式。

内容的提问来源于stack exchange,提问作者Denzen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 02:55:18