Nullable CupertinoThemeData.brightness
Summary
#CupertinoThemeData.brightness is now nullable.
Context
#CupertinoThemeData.brightness is now used to override MediaQuery.platformBrightness for Cupertino widgets. Before this change, the CupertinoThemeData.brightness getter returned Brightness.light when it was set to null.
Description of change
#Previously CupertinoThemeData.brightness was implemented as a getter:
Brightness get brightness => _brightness ?? Brightness.light;
final Brightness _brightness;It is now a stored property:
final Brightness brightness;Migration guide
#Generally CupertinoThemeData.brightness is rarely useful outside of the Flutter framework. To retrieve the brightness for Cupertino widgets, now use CupertinoTheme.brightnessOf instead.
With this change, it is now possible to override CupertinoThemeData.brightness in a CupertinoThemeData subclass to change the brightness override. For example:
class AlwaysDarkCupertinoThemeData extends CupertinoThemeData {
Brightness brightness => Brightness.dark;
}When a CupertinoTheme uses the above CupertinoThemeData, dark mode is enabled for all its Cupertino descendants that are affected by this CupertinoTheme.
Timeline
#Landed in version: 1.16.3
In stable release: 1.17
References
#Design doc:
API documentation:
Relevant issue:
Relevant PR:
除非另有说明,否则本网站上的文档反映的是 Flutter 的最新稳定版本。页面最后更新于 2025-01-30。 查看源代码 或 报告问题。