refreshDisplays method

Future<List<DVDisplay>> refreshDisplays()

Re-reads the display list and publishes it to displays.

Prefers the window.displays native binding, which reports what the OS knows -- layout origins, panel names, which display is primary. Without it, Flutter's own PlatformDispatcher.displays still gives size, pixel ratio and refresh rate for every display, and unlike the desktop windowing API it is stable rather than behind an experimental flag. What it cannot give is where the displays sit relative to each other, which DVDisplay.hasLayout reports rather than invents.

Never throws. Failing to enumerate displays should cost the display list, not the launch.

Implementation

Future<List<DVDisplay>> refreshDisplays() async {
  List<DVDisplay> found = const <DVDisplay>[];
  try {
    final Object? payload = DVNativeBridge.isRegistered('window.displays')
        ? await DVNativeBridge.invoke<Object?>('window.displays')
        : _flutterDisplays();
    found = DVDisplays.decode(payload, profile: displayProfile);
  } on Object {
    found = const <DVDisplay>[];
  }
  _displays.value = List<DVDisplay>.unmodifiable(found);
  return _displays.value;
}