buildDefaultDragHandles property

bool buildDefaultDragHandles
final

If true: on desktop platforms, a drag handle is stacked over the center of each item's trailing edge; on mobile platforms, a long press anywhere on the item starts a drag.

The default desktop drag handle is just an Icons.drag_handle wrapped by a ReorderableDragStartListener. On mobile platforms, the entire item is wrapped with a ReorderableDelayedDragStartListener.

To change the appearance or the layout of the drag handles, make this parameter false and wrap each list item, or a widget within each list item, with ReorderableDragStartListener or ReorderableDelayedDragStartListener, or a custom subclass of ReorderableDragStartListener.

The following sample specifies buildDefaultDragHandles: false, and uses a Card at the leading edge of each item for the item's drag handle.

To see it in action, copy and run this code snippet on DartPad.

import 'package:material_ui/material_ui.dart';

/// Flutter code sample for [ReorderableListView.buildDefaultDragHandles].

void main() => runApp(const ReorderableApp());

class ReorderableApp extends StatelessWidget {
  const ReorderableApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('ReorderableListView Sample')),
        body: const ReorderableExample(),
      ),
    );
  }
}

class ReorderableExample extends StatefulWidget {
  const ReorderableExample({super.key});

  @override
  State<ReorderableExample> createState() => _ReorderableExampleState();
}

class _ReorderableExampleState extends State<ReorderableExample> {
  final List<int> _items = List<int>.generate(50, (int index) => index);

  @override
  Widget build(BuildContext context) {
    final ColorScheme colorScheme = Theme.of(context).colorScheme;
    final Color oddItemColor = colorScheme.primary.withValues(alpha: 0.05);
    final Color evenItemColor = colorScheme.primary.withValues(alpha: 0.15);

    return ReorderableListView(
      buildDefaultDragHandles: false,
      children: <Widget>[
        for (int index = 0; index < _items.length; index++)
          ColoredBox(
            key: Key('$index'),
            color: _items[index].isOdd ? oddItemColor : evenItemColor,
            child: Row(
              children: <Widget>[
                Container(
                  width: 64,
                  height: 64,
                  padding: const .all(8),
                  child: ReorderableDragStartListener(
                    index: index,
                    child: Card(color: colorScheme.primary, elevation: 2),
                  ),
                ),
                Text('Item ${_items[index]}'),
              ],
            ),
          ),
      ],
      onReorderItem: (int oldIndex, int newIndex) {
        setState(() {
          final int item = _items.removeAt(oldIndex);
          _items.insert(newIndex, item);
        });
      },
    );
  }
}

Implementation

// TODO(framework): Replace the following block with a @dartpad directive
// when it's supported. https://github.com/dart-lang/dartdoc/issues/4123
/// {@macro material_ui.dartpad_guide}
///
/// {@example /example/lib/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart#body}
///
/// </callout-box>
final bool buildDefaultDragHandles;