searchOptions method

Future<OptionsPage> searchOptions(
  1. String field,
  2. String query
)

The options for a select whose list /schema refused to inline.

Carries the form's current values, because options depend on siblings: a pilot measured a dependent picker narrowing 6 -> 2 -> 1 as its parent changed, and sending an empty map makes every dependent select wrong.

Implementation

Future<OptionsPage> searchOptions(String field, String query) async {
  // Per-field sequencing, the same guard `/state` carries: a search box types
  // fast, and the first response resolving last must be dropped. P1 shipped
  // this bug in ResourceListProvider and it has been guarded twice since.
  final id = (_optionsId[field] ?? 0) + 1;
  _optionsId[field] = id;

  try {
    final page = await source.options(
      resource.key,
      field: field,
      recordId: recordId,
      values: _values.payloadFor(_components),
      query: query,
    );

    if (_optionsId[field] != id) return _pageFor(field);

    _optionsPages[field] = page;
    _notify();

    return page;
  } catch (e) {
    // Degrade, never block — the same rule `/state` follows. A picker that
    // cannot reach the server shows what it already had; it does not take
    // the form down, and it is deliberately not surfaced in [formError],
    // which is the save banner.
    return _pageFor(field);
  }
}