解决 Flutter ReorderableListView remove menu button 拖拽上的图标删除

4 min read
                          Expanded(
                            child: ReorderableListView(
                              buildDefaultDragHandles: false,
                              onReorder: onReorder,
                              children: _getListItems(),
                            ),
                          ),

增加 buildDefaultDragHandles 属性禁用默认行为样式,禁止后无法再进行列表的拖拽

然后重写onReorder方法 , 就是对传入的列表项进行相关的操作

  void onReorder(int oldIndex, int newIndex) {
    if (newIndex > oldIndex) {
      newIndex -= 1;
    }

    setState(() {
      CommentItem comment = _comments[oldIndex];
      _comments.removeAt(oldIndex);
      _comments.insert(newIndex, comment);
    });
  }