ExpandableReorderableList<K extends Key> constructor

ExpandableReorderableList<K extends Key>({
  1. List<Widget> leads = const <Widget>[],
  2. List<Widget> tails = const <Widget>[],
  3. List<ExpandableReorderableListItem<K>>? children,
  4. OnReorder<K>? onReorder,
  5. ScrollController? scrollController,
  6. VisibilityController<K>? visibilityController,
  7. ExpandableReorderableListItemModelController<K>? modelsController,
  8. Key? key,
})

An expandable reorderable list.

If onReorder is specified, it builds a ReorderableListView, if not, it builds a ListView.


This example, inspired by the ReorderableListView documentation, creates a list using ExpandableReorderableList:

 final List<int> _items = List<int>.generate(50, (index) => index);

 @override
 Widget build(BuildContext context) {
   final colorScheme = Theme.of(context).colorScheme;
   final oddItemColor = colorScheme.primary.withOpacity(0.05);
   final evenItemColor = colorScheme.primary.withOpacity(0.15);
   return ExpandableReorderableList<ValueKey<int>>(
     onReorder: (onReorderParam) {
       setState(() {
         var newIndex = onReorderParam.newIndex;
         if (onReorderParam.oldIndex < onReorderParam.newIndex) {
           newIndex -= 1;
         }
         final int item = _items.removeAt(onReorderParam.oldIndex);
         _items.insert(newIndex, item);
       });
     },
     children: _items.map((int item) {
       return ExpandableReorderableListItem<ValueKey<int>>(
         key: ValueKey<int>(item),
         builder: (_, child, model) {
           return ReorderableDragStartListener(
             index: model.index!,
             child: ListTile(
               title: Text('Item $item'),
               tileColor: item.isOdd ? oddItemColor : evenItemColor,
             ),
           );
         },
       );
     }).toList(),
   );
 }

Implementation

ExpandableReorderableList({
  this.leads = const <Widget>[],
  this.tails = const <Widget>[],
  List<ExpandableReorderableListItem<K>>? children,
  this.onReorder,
  this.scrollController,
  this.visibilityController,
  this.modelsController,
  Key? key,
})  : children = children ?? <ExpandableReorderableListItem<K>>[],
      super(key: key);