saveReorder method

Future<void> saveReorder()

Commits the current drag order: POST {resource}/reorder with every record CURRENTLY VISIBLE's id, first entry first — the searched subset when a search term is active, same as _fetchReorderedPage fetched. This matches Filament's own reorder-while-filtered behavior: the server renumbers only the posted ids 1..N among themselves, leaving records outside the filter wherever they already were.

Optimistic in the sense that the local order is already what the user sees — this call either confirms it (exit reorder mode, then refresh the normal paginated list so it reflects the new order) or rolls it back to the last server-confirmed order and surfaces errorMessage, same as every other write in this package.

Implementation

Future<void> saveReorder() async {
  // Outruns any reorder-search fetch already in flight — its response must
  // not land on top of the order this save is about to commit.
  ++_requestId;
  _isSavingReorder = true;
  _errorMessage = null;
  notifyListeners();

  try {
    await source.reorder(resource.key, [
      for (final record in _reorderedRecords) record.id,
    ]);
    _isSavingReorder = false;
    _isReordering = false;
    notifyListeners();
    await refresh();
  } catch (e) {
    _reorderedRecords = _serverReorderedRecords;
    _errorMessage = messageOf(e);
    _isSavingReorder = false;
    notifyListeners();
  }
}