load method

Future<void> load()

Updates the fetched accent colors on Windows.

Implementation

Future<void> load() async {
  WidgetsFlutterBinding.ensureInitialized();

  try {
    final colors = await _channel.invokeMethod(kGetSystemAccentColorMethod);
    if (colors == null) return;

    accent = _retrieve(colors['accent'])!;
    light = _retrieve(colors['light']) ?? accent;
    lighter = _retrieve(colors['lighter']) ?? accent;
    lightest = _retrieve(colors['lightest']) ?? accent;
    dark = _retrieve(colors['dark']) ?? accent;
    darker = _retrieve(colors['darker']) ?? accent;
    darkest = _retrieve(colors['darkest']) ?? accent;
  } on MissingPluginException {
    debugPrint('system_theme does not implement the current platform');
    return;
  } catch (_) {
    rethrow;
  }

  _subscription ??= SystemTheme.onChange.listen((color) {
    accent = color.accent;
    light = color.light;
    lighter = color.lighter;
    lightest = color.lightest;
    dark = color.dark;
    darker = color.darker;
    darkest = color.darkest;
  });
}