CupertinoThemeData.brightness 现可为空


CupertinoThemeData.brightness is now nullable.


CupertinoThemeData.brightness is used to override MediaQuery.platformBrightness for Cupertino widgets. Before this change, the CupertinoThemeData.brightness getter returns Brightness.light when it’s 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, 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 AwaysDarkCupertinoThemeData extends CupertinoThemeData {
  Brightness brightness => Brightness.dark;

when a CupertinoTheme uses the above CupertinoThemeData, dark mode will be enabled for all its Cupertino descendants that are affected by this CupertinoTheme.


This change was made in January of 2020 after the v1.13.7 release.


Design doc:

API documentation:

Relevant issues:

Relevant PRs: