Flutter中如何实现DataTable组件拉伸至最大宽度全宽显示
问题说明
- 需要让
DataTable组件拉伸至容器最大可用宽度,当前展示效果未达到预期 - 曾尝试使用
ConstrainedBox设置宽度约束,操作后约束逻辑未生效,还抛出了运行时错误
表格功能实现代码
SingleChildScrollView _dataBody() { return SingleChildScrollView( scrollDirection: Axis.vertical, child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: DataTable( headingRowColor: MaterialStateColor.resolveWith((states) => Color(0xFF2F80ED)), headingTextStyle: TextStyle(color: Colors.white), columns: [ DataColumn(label: Text('ID')), DataColumn(label: Text('Name')), DataColumn(label: Text('Surname')), DataColumn(label: Text('Birth date')), DataColumn(label: Text('Algebra')), DataColumn(label: Text('Chemistry')), DataColumn(label: Text('Programing')) ], rows: _students .map((student) => DataRow(cells: [ DataCell(Text(student.id)), DataCell(Text(student.firstName.toString())), DataCell(Text(student.lastName.toString())), DataCell(Text(student.birthDate.toString())), DataCell(Text(student.algebra.toString())), DataCell(Text(student.chemistry.toString())), DataCell(Text(student.programing.toString())) ])) .toList()), ), ); }
表格组件的挂载页面布局代码
Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ SizedBox( height: 110, child: Container(), ), Expanded( child: _dataBody(), ) ], ))
内容的提问来源于stack exchange,提问作者Zimme
相关产品推荐
相关产品推荐

