Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

flutter - 如何将数据表转换为listview.builder?(How to transform datatable to listview.builder?)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...