【问题标题】:Add separator to ListTile将分隔符添加到 ListTile
【发布时间】:2020-11-01 07:14:36
【问题描述】:

我想在我的列表中包含分隔符,但我的 _buildTenableListTile() 函数返回一个 ListTile()。

如何才能在列表中包含分隔符?

  Widget _buildReorderableListSimple(BuildContext context) {
    return ReorderableListView(
      onReorder: _onReorder,
      children: _getListItems(),
    );
  }

  List<ListTile> _getListItems() => _items
      .asMap()
      .map((i, item) => MapEntry(i, _buildTenableListTile(item, i)))
      .values
      .toList();

  ListTile _buildTenableListTile(Song item, int index) {
    return ListTile(
      key: ValueKey(item.songId),
      title: new Text(
        '${item.sequence}. ${item.name}',
        style: TextStyle(
          color: Colors.black,
          fontWeight: FontWeight.bold,
        ),
      ),
      subtitle: new Text(
        '${item.artist} ${item.songId}',
        style: TextStyle(
          color: Colors.black,
        ),
      ),
      onTap: () {

      },
    );
  }

【问题讨论】:

    标签: flutter


    【解决方案1】:

    _getListItems 更改为如下内容:

    ListView.separated(
      itemCount: _items.length,
      itemBuilder: (context, index) {
        return _buildTenableListTile(_items[index],index);
      },
      separatorBuilder: (context, index) {
        return Divider();
      },
    )
    

    【讨论】:

    • type 'ListView' 不是 type 'List' 的子类型
    • _getListItems() { return ListView.separated( itemCount: _items.length, itemBuilder: (context, index) { return _buildTenableListTile(_items[index], index); }, separatorBuilder: (context, index ) { 返回分频器(); }); }
    • ReorderableListView 小部件接收一个 List,而不是 ListView。
    • @AlexandreMarques 好的检查here
    猜你喜欢
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    • 2021-02-22
    • 2013-06-17
    • 2014-09-28
    相关资源
    最近更新 更多