I have a function that use dataTable widget.
(我有一个使用dataTable小部件的函数。)
But I need to use ListView.Builder widget instead dataTable. (但是我需要使用ListView.Builder小部件而不是dataTable。)
How I can transform this function? (如何转换此功能?)
Some code: (一些代码:)
SingleChildScrollView _dataCol() {
return SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
child: CustomDataTable(
columns: [
CustomDataColumn(label: Text('')),],
rows: List<int>.generate(max(_filterEmployees.length, 11), (i) => i)
.map((num) {
if (num < _filterEmployees.length) {
return _filterEmployees[num];
}
return Employee();})
.map(
(employee) => CustomDataRow(cells: [
CustomDataCell(
Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.41),
width: MediaQuery.of(context).size.width * 0.28 +
_scrollBarOffset,
child: Text(
employee.facName != null ? employee.facName : '',
style: TextStyle(
color: Color.fromARGB(255, 39, 58, 77),
fontWeight: FontWeight.w500,
fontSize: 12,
),
overflow: TextOverflow.ellipsis,
maxLines: 2,
),),onTap: () {
...});},),]),).toList(),),),);}
I try to do this, Here is my code for listview.builder, but it doesn't work.
(我尝试执行此操作,这是我的listview.builder代码,但不起作用。)
I see RangeError: (我看到RangeError:)
ListView _dataCol() {
return new ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: _filterEmployees == null ? 0 : _filterEmployees.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(
_facNameController.text[index] != null
? _facNameController.text[index]
: '',
style: TextStyle(
color: Color.fromARGB(255, 39, 58, 77),
fontWeight: FontWeight.w500,
fontSize: 12,
),
overflow: TextOverflow.ellipsis,
maxLines: 2,
));
});
}
ask by WhyTooHard translate from so