Reorderable list
Use a reorderable list when the sequence belongs to the reader. Give each item a stable identity so moving a row keeps its text and focus together.
Order the stops
#Move Park below Market, then move it back. A row labelled Make first can also be activated to bring that stop to the top.
Drag the grip to reorder a row, or activate Move first down with the keyboard.
components/reorderable-list/appliance/order_stops.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class OrderStops extends StatefulWidget {
const OrderStops({super.key});
@override
State<OrderStops> createState() => _OrderStopsState();
}
class _OrderStopsState extends State<OrderStops> {
final stops = ['Park', 'Market', 'Pier'];
void move(int from, int to) {
setState(() {
final stop = stops.removeAt(from);
stops.insert(to, stop);
});
}
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 440),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 150,
child: ApplianceReorderableList<String>(
items: stops,
labelOf: (stop) => stop,
title: (stop) => stop,
onReorder: move,
),
),
const SizedBox(height: 12),
ApplianceButton('Move first down', onPressed: () => move(0, 1)),
],
),
);
}
Parameters
ApplianceReorderableList API ↗items- The items, in order.
onReorder- Moves the item at the first index to the second.
labelOf- An item's name for a screen reader.
title- A row's words.
subtitle- A row's second line.
shrinkWrap- Whether it is as tall as its rows (inside another scroll view).
Shared behaviour
- Keyboard and focus. Tab to a stop and activate Make first to move it to the start. Where the look handles Alt with Up or Down, those keys move the focused stop one position. The look’s note gives any other controls.
- Screen readers. Read the order of the stops after moving one. Check the move actions the look exposes on each item.
- Direction and type. The route still runs from top to bottom in RTL. Larger type should leave room for each stop and its handle.