flutter 在表格抖动中添加图标按钮

qrjkbowd  于 2023-01-31  发布在  Flutter
关注(0)|答案(1)|浏览(175)
body: Container(
      padding: EdgeInsets.all(25),
      child: Table(
        border: TableBorder.all(),
        columnWidths: {
          0: FractionColumnWidth(0.14),
          1: FractionColumnWidth(0.6),
          2: FractionColumnWidth(0.3),
        },
        children: [
         // here to add iconButton
          buildRow(['No.','List of Books','Action'], isHeader: true),
          buildRow(['1','Harry Potter Philosopher','Action']),
          buildRow(['2','Sleeping Beauty','Action']),
          buildRow(['3','Beauty and The Beast','Action']),
        ],
      ),
    ),
  );

   // here List<String>
  TableRow buildRow(List<String> cells, {bool isHeader = false}) => TableRow(
    children: cells.map((cell) {
      final style = TextStyle(
        fontWeight: isHeader? FontWeight.bold : FontWeight.normal,
        fontSize: 18,
      );
      return Padding(
        padding: const EdgeInsets.all(12),
        child: Center(
          child: Text(
            (cell), //here error
            style: TextStyle(
              fontWeight: FontWeight.bold,
              fontSize: 15,
            ),
          ),
        ),
      );
    }).toList(),
  );
}

这里是我混淆声明图标按钮参数buildRow的原因,它携带字符串,但当我改变为小部件,它会出现在文本(单元格)的错误。我想添加的iconButton在第三行的表格

rqqzpn5f

rqqzpn5f1#

只需将List<Strings> cells声明为List<Widgets> cells,如下所示:

这样使用:

buildRow([Text('1'), IconButton(onPressed: (){}, icon: Icon(Icons.edit))], isHeader: true),

相关问题