Migrate to Theme.brightnessOf method (#163950)
Refactor: Migrate to Theme.brightnessOf method fixes: #163837 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
This commit is contained in:
@@ -30,7 +30,7 @@ class _InputDropdown extends StatelessWidget {
|
||||
Icon(
|
||||
Icons.arrow_drop_down,
|
||||
color:
|
||||
Theme.of(context).brightness == Brightness.light
|
||||
Theme.brightnessOf(context) == Brightness.light
|
||||
? Colors.grey.shade700
|
||||
: Colors.white70,
|
||||
),
|
||||
|
||||
@@ -77,7 +77,7 @@ class MenuDemoState extends State<MenuDemo> {
|
||||
),
|
||||
body: ListTileTheme(
|
||||
iconColor:
|
||||
Theme.of(context).brightness == Brightness.light ? Colors.grey[600] : Colors.grey[500],
|
||||
Theme.brightnessOf(context) == Brightness.light ? Colors.grey[600] : Colors.grey[500],
|
||||
child: ListView(
|
||||
padding: kMaterialListPadding,
|
||||
children: <Widget>[
|
||||
|
||||
@@ -169,7 +169,7 @@ class _GalleryAppState extends State<GalleryApp> {
|
||||
Builder(
|
||||
builder: (BuildContext context) {
|
||||
return CupertinoTheme(
|
||||
data: CupertinoThemeData(brightness: Theme.of(context).brightness),
|
||||
data: CupertinoThemeData(brightness: Theme.brightnessOf(context)),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
|
||||
@@ -187,7 +187,7 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final SyntaxHighlighterStyle style =
|
||||
Theme.of(context).brightness == Brightness.dark
|
||||
Theme.brightnessOf(context) == Brightness.dark
|
||||
? SyntaxHighlighterStyle.darkThemeStyle
|
||||
: SyntaxHighlighterStyle.lightThemeStyle;
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ class _BooleanItem extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final bool isDark = Theme.brightnessOf(context) == Brightness.dark;
|
||||
return _OptionsItem(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
|
||||
@@ -77,7 +77,7 @@ class _ReplyAppState extends State<ReplyApp> with RestorationMixin {
|
||||
final ThemeMode galleryThemeMode = GalleryOptions.of(context).themeMode;
|
||||
final bool isDark =
|
||||
galleryThemeMode == ThemeMode.system
|
||||
? Theme.of(context).brightness == Brightness.dark
|
||||
? Theme.brightnessOf(context) == Brightness.dark
|
||||
: galleryThemeMode == ThemeMode.dark;
|
||||
|
||||
final ThemeData replyTheme =
|
||||
|
||||
@@ -288,7 +288,7 @@ class _MailPreviewActionBar extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final bool isDark = Theme.brightnessOf(context) == Brightness.dark;
|
||||
final Color color = isDark ? ReplyColors.white50 : ReplyColors.blue600;
|
||||
final bool isDesktop = isDisplayDesktop(context);
|
||||
final Color starredIconColor = isStarred ? Theme.of(context).colorScheme.secondary : color;
|
||||
|
||||
@@ -298,7 +298,7 @@ class _BottomAppBarDefaultsM2 extends BottomAppBarTheme {
|
||||
|
||||
@override
|
||||
Color? get color =>
|
||||
Theme.of(context).brightness == Brightness.dark ? Colors.grey[800]! : Colors.white;
|
||||
Theme.brightnessOf(context) == Brightness.dark ? Colors.grey[800]! : Colors.white;
|
||||
|
||||
@override
|
||||
Color? get surfaceTintColor => Theme.of(context).colorScheme.surfaceTint;
|
||||
|
||||
@@ -1465,7 +1465,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
|
||||
|
||||
Color get _iconColor {
|
||||
// These colors are not defined in the Material Design spec.
|
||||
final Brightness brightness = Theme.of(context).brightness;
|
||||
final Brightness brightness = Theme.brightnessOf(context);
|
||||
if (_enabled) {
|
||||
return widget.iconEnabledColor ??
|
||||
switch (brightness) {
|
||||
|
||||
@@ -173,7 +173,7 @@ class _ExpandIconState extends State<ExpandIcon> with SingleTickerProviderStateM
|
||||
return widget.color!;
|
||||
}
|
||||
|
||||
return switch (Theme.of(context).brightness) {
|
||||
return switch (Theme.brightnessOf(context)) {
|
||||
Brightness.light => Colors.black54,
|
||||
Brightness.dark => Colors.white60,
|
||||
};
|
||||
|
||||
@@ -1002,7 +1002,7 @@ class _IconButtonM3 extends ButtonStyleButton {
|
||||
ButtonStyle? themeStyleOf(BuildContext context) {
|
||||
final IconThemeData iconTheme = IconTheme.of(context);
|
||||
final bool isDefaultSize = iconTheme.size == const IconThemeData.fallback().size;
|
||||
final bool isDefaultColor = identical(iconTheme.color, switch (Theme.of(context).brightness) {
|
||||
final bool isDefaultColor = identical(iconTheme.color, switch (Theme.brightnessOf(context)) {
|
||||
Brightness.light => kDefaultIconDarkColor,
|
||||
Brightness.dark => kDefaultIconLightColor,
|
||||
});
|
||||
|
||||
@@ -5070,7 +5070,7 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme {
|
||||
|
||||
@override
|
||||
Color? get fillColor => MaterialStateColor.resolveWith((Set<MaterialState> states) {
|
||||
return switch ((Theme.of(context).brightness, states.contains(MaterialState.disabled))) {
|
||||
return switch ((Theme.brightnessOf(context), states.contains(MaterialState.disabled))) {
|
||||
(Brightness.dark, true) => const Color(0x0DFFFFFF), // 5% white
|
||||
(Brightness.dark, false) => const Color(0x1AFFFFFF), // 10% white
|
||||
(Brightness.light, true) => const Color(0x05000000), // 2% black
|
||||
@@ -5086,7 +5086,7 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme {
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return Theme.of(context).colorScheme.primary;
|
||||
}
|
||||
return switch (Theme.of(context).brightness) {
|
||||
return switch (Theme.brightnessOf(context)) {
|
||||
Brightness.dark => Colors.white70,
|
||||
Brightness.light => Colors.black45,
|
||||
};
|
||||
@@ -5100,7 +5100,7 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme {
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return Theme.of(context).colorScheme.primary;
|
||||
}
|
||||
return switch (Theme.of(context).brightness) {
|
||||
return switch (Theme.brightnessOf(context)) {
|
||||
Brightness.dark => Colors.white70,
|
||||
Brightness.light => Colors.black45,
|
||||
};
|
||||
@@ -5117,7 +5117,7 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme {
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return Theme.of(context).colorScheme.primary;
|
||||
}
|
||||
return switch (Theme.of(context).brightness) {
|
||||
return switch (Theme.brightnessOf(context)) {
|
||||
Brightness.dark => Colors.white70,
|
||||
Brightness.light => Colors.black45,
|
||||
};
|
||||
|
||||
@@ -430,7 +430,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
|
||||
}
|
||||
|
||||
bool _isDark() {
|
||||
return Theme.of(context).brightness == Brightness.dark;
|
||||
return Theme.brightnessOf(context) == Brightness.dark;
|
||||
}
|
||||
|
||||
bool _isLabel() {
|
||||
@@ -593,7 +593,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
|
||||
);
|
||||
}
|
||||
|
||||
final Color cancelColor = switch (Theme.of(context).brightness) {
|
||||
final Color cancelColor = switch (Theme.brightnessOf(context)) {
|
||||
Brightness.light => Colors.black54,
|
||||
Brightness.dark => Colors.white70,
|
||||
};
|
||||
|
||||
@@ -2630,7 +2630,7 @@ class _TabsDefaultsM2 extends TabBarThemeData {
|
||||
|
||||
final BuildContext context;
|
||||
late final ColorScheme _colors = Theme.of(context).colorScheme;
|
||||
late final bool isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
late final bool isDark = Theme.brightnessOf(context) == Brightness.dark;
|
||||
late final Color primaryColor = isDark ? Colors.grey[900]! : Colors.blue;
|
||||
final bool isScrollable;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user