diff --git a/lib/system_theme.dart b/lib/system_theme.dart index 0fc9a92..956b0d4 100644 --- a/lib/system_theme.dart +++ b/lib/system_theme.dart @@ -1,4 +1,6 @@ -import 'package:flutter/services.dart' show MethodChannel, Color; +import 'package:flutter/foundation.dart' show debugPrint; +import 'package:flutter/services.dart' + show Color, MethodChannel, MissingPluginException; import 'package:flutter/widgets.dart' show WidgetsFlutterBinding; /// Default system accent color. @@ -74,16 +76,23 @@ class SystemAccentColor { Future load() async { WidgetsFlutterBinding.ensureInitialized(); - 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; + 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 the current platform'); + return; + } catch (_) { + rethrow; + } } Color? _retrieve(dynamic map) {