maybeBrightnessOf static method
Retrieves the Brightness to use for descendant macOS widgets, based
on the value of MacosThemeData.brightness in the given context
.
If no MacosTheme can be found in the given context
, it will fall
back to MediaQueryData.platformBrightness.
Returns null if no valid MacosTheme or MediaQuery widgets exist in the ancestry tree.
See also:
- MacosThemeData.brightness, the property takes precedence over MediaQueryData.platformBrightness for descendant macOS widgets.
- brightnessOf, which throws if no valid MacosTheme or MediaQuery exists, instead of returning null.
Implementation
static Brightness? maybeBrightnessOf(BuildContext context) {
final _InheritedMacosTheme? inheritedTheme =
context.dependOnInheritedWidgetOfExactType<_InheritedMacosTheme>();
return inheritedTheme?.theme.data.brightness ??
MediaQuery.maybeOf(context)?.platformBrightness;
}