Skip to content

Commit

Permalink
Remove brightness from AppBar/SliverAppBar/AppBarTheme/`AppBa…
Browse files Browse the repository at this point in the history
…rTheme.copyWith` (#120575)
  • Loading branch information
QuncCccccc authored Feb 13, 2023
1 parent 73afc7b commit f858302
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 107 deletions.
71 changes: 6 additions & 65 deletions packages/flutter/lib/src/material/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
this.shape,
this.backgroundColor,
this.foregroundColor,
@Deprecated(
'This property is no longer used, please use systemOverlayStyle instead. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
this.brightness,
this.iconTheme,
this.actionsIconTheme,
this.primary = true,
Expand Down Expand Up @@ -499,7 +494,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// If null, then the [AppBarTheme.backgroundColor] is used. If that value is also
/// null, then [AppBar] uses the overall theme's [ColorScheme.primary] if the
/// overall theme's brightness is [Brightness.light], and [ColorScheme.surface]
/// if the overall theme's [brightness] is [Brightness.dark].
/// if the overall theme's brightness is [Brightness.dark].
///
/// If this color is a [MaterialStateColor] it will be resolved against
/// [MaterialState.scrolledUnder] when the content of the app's
Expand All @@ -525,7 +520,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// value is also null, then [AppBar] uses the overall theme's
/// [ColorScheme.onPrimary] if the overall theme's brightness is
/// [Brightness.light], and [ColorScheme.onSurface] if the overall
/// theme's [brightness] is [Brightness.dark].
/// theme's brightness is [Brightness.dark].
///
/// This color is used to configure [DefaultTextStyle] that contains
/// the toolbar's children, and the default [IconTheme] widgets that
Expand All @@ -543,38 +538,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// is light or dark.
final Color? foregroundColor;

/// {@template flutter.material.appbar.brightness}
/// This property is deprecated, please use [systemOverlayStyle] instead.
///
/// Determines the brightness of the [SystemUiOverlayStyle]: for
/// [Brightness.dark], [SystemUiOverlayStyle.light] is used and for
/// [Brightness.light], [SystemUiOverlayStyle.dark] is used.
///
/// If this value is null then [AppBarTheme.brightness] is used
/// and if that's null then overall theme's brightness is used.
///
/// The AppBar is built within a `AnnotatedRegion<SystemUiOverlayStyle>`
/// which causes [SystemChrome.setSystemUIOverlayStyle] to be called
/// automatically. Apps should not enclose the AppBar with
/// their own [AnnotatedRegion].
/// {@endtemplate}
///
/// See also:
///
/// * [Theme.of], which returns the current overall Material theme as
/// a [ThemeData].
/// * [ThemeData.colorScheme], the thirteen colors that most Material widget
/// default colors are based on.
/// * [ColorScheme.brightness], which indicates if the overall [Theme]
/// is light or dark.
/// * [backwardsCompatibility], which forces AppBar to use this
/// obsolete property.
@Deprecated(
'This property is no longer used, please use systemOverlayStyle instead. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
final Brightness? brightness;

/// {@template flutter.material.appbar.iconTheme}
/// The color, opacity, and size to use for toolbar icons.
///
Expand Down Expand Up @@ -692,8 +655,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// This property is deprecated and is false by default.
///
/// If true, preserves the original defaults for the [backgroundColor],
/// [iconTheme], [actionsIconTheme] properties, and the original use of
/// the [brightness] property.
/// [iconTheme], [actionsIconTheme] properties.
///
/// If this property is null, then [AppBarTheme.backwardsCompatibility] of
/// [ThemeData.appBarTheme] is used. If that is also null, the default
Expand Down Expand Up @@ -1212,11 +1174,9 @@ class _AppBarState extends State<AppBar> {
}

final SystemUiOverlayStyle overlayStyle = backwardsCompatibility
? _systemOverlayStyleForBrightness(
widget.brightness
?? appBarTheme.brightness
?? ThemeData.estimateBrightnessForColor(backgroundColor),
)
? widget.systemOverlayStyle
?? appBarTheme.systemOverlayStyle
?? _systemOverlayStyleForBrightness(ThemeData.estimateBrightnessForColor(backgroundColor))
: widget.systemOverlayStyle
?? appBarTheme.systemOverlayStyle
?? defaults.systemOverlayStyle
Expand Down Expand Up @@ -1269,7 +1229,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
required this.forceElevated,
required this.backgroundColor,
required this.foregroundColor,
required this.brightness,
required this.iconTheme,
required this.actionsIconTheme,
required this.primary,
Expand Down Expand Up @@ -1309,7 +1268,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
final bool forceElevated;
final Color? backgroundColor;
final Color? foregroundColor;
final Brightness? brightness;
final IconThemeData? iconTheme;
final IconThemeData? actionsIconTheme;
final bool primary;
Expand Down Expand Up @@ -1385,7 +1343,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
surfaceTintColor: surfaceTintColor,
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
brightness: brightness,
iconTheme: iconTheme,
actionsIconTheme: actionsIconTheme,
primary: primary,
Expand Down Expand Up @@ -1420,7 +1377,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|| shadowColor != oldDelegate.shadowColor
|| backgroundColor != oldDelegate.backgroundColor
|| foregroundColor != oldDelegate.foregroundColor
|| brightness != oldDelegate.brightness
|| iconTheme != oldDelegate.iconTheme
|| actionsIconTheme != oldDelegate.actionsIconTheme
|| primary != oldDelegate.primary
Expand Down Expand Up @@ -1555,11 +1511,6 @@ class SliverAppBar extends StatefulWidget {
this.forceElevated = false,
this.backgroundColor,
this.foregroundColor,
@Deprecated(
'This property is no longer used, please use systemOverlayStyle instead. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
this.brightness,
this.iconTheme,
this.actionsIconTheme,
this.primary = true,
Expand Down Expand Up @@ -1865,15 +1816,6 @@ class SliverAppBar extends StatefulWidget {
/// This property is used to configure an [AppBar].
final Color? foregroundColor;

/// {@macro flutter.material.appbar.brightness}
///
/// This property is used to configure an [AppBar].
@Deprecated(
'This property is no longer used, please use systemOverlayStyle instead. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
final Brightness? brightness;

/// {@macro flutter.material.appbar.iconTheme}
///
/// This property is used to configure an [AppBar].
Expand Down Expand Up @@ -2149,7 +2091,6 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix
forceElevated: widget.forceElevated,
backgroundColor: widget.backgroundColor,
foregroundColor: widget.foregroundColor,
brightness: widget.brightness,
iconTheme: widget.iconTheme,
actionsIconTheme: widget.actionsIconTheme,
primary: widget.primary,
Expand Down
33 changes: 0 additions & 33 deletions packages/flutter/lib/src/material/app_bar_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ import 'theme.dart';
class AppBarTheme with Diagnosticable {
/// Creates a theme that can be used for [ThemeData.appBarTheme].
const AppBarTheme({
@Deprecated(
'This property is no longer used, please use systemOverlayStyle instead. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
this.brightness,
Color? color,
Color? backgroundColor,
this.foregroundColor,
Expand Down Expand Up @@ -59,24 +54,6 @@ class AppBarTheme with Diagnosticable {
),
backgroundColor = backgroundColor ?? color;

/// This property is deprecated, please use [systemOverlayStyle] instead.
///
/// Overrides the default value of the obsolete [AppBar.brightness]
/// property which implicitly defines [AppBar.systemOverlayStyle] in
/// all descendant [AppBar] widgets.
///
/// See also:
///
/// * [systemOverlayStyle], which overrides the default value of
/// [AppBar.systemOverlayStyle] in all descendant [AppBar] widgets.
/// * [AppBar.backwardsCompatibility], which forces [AppBar] to depend
/// on this obsolete property.
@Deprecated(
'This property is no longer used, please use systemOverlayStyle instead. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
final Brightness? brightness;

/// This property is deprecated, please use [backgroundColor] instead.
///
/// Obsolete property that overrides the default value of
Expand Down Expand Up @@ -214,11 +191,6 @@ class AppBarTheme with Diagnosticable {
/// new values.
AppBarTheme copyWith({
IconThemeData? actionsIconTheme,
@Deprecated(
'This property is no longer used, please use systemOverlayStyle instead. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
Brightness? brightness,
Color? color,
Color? backgroundColor,
Color? foregroundColor,
Expand All @@ -245,7 +217,6 @@ class AppBarTheme with Diagnosticable {
'The color and backgroundColor parameters mean the same thing. Only specify one.',
);
return AppBarTheme(
brightness: brightness ?? this.brightness,
backgroundColor: backgroundColor ?? color ?? this.backgroundColor,
foregroundColor: foregroundColor ?? this.foregroundColor,
elevation: elevation ?? this.elevation,
Expand Down Expand Up @@ -277,7 +248,6 @@ class AppBarTheme with Diagnosticable {
/// {@macro dart.ui.shadow.lerp}
static AppBarTheme lerp(AppBarTheme? a, AppBarTheme? b, double t) {
return AppBarTheme(
brightness: t < 0.5 ? a?.brightness : b?.brightness,
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t),
elevation: lerpDouble(a?.elevation, b?.elevation, t),
Expand All @@ -299,7 +269,6 @@ class AppBarTheme with Diagnosticable {

@override
int get hashCode => Object.hash(
brightness,
backgroundColor,
foregroundColor,
elevation,
Expand Down Expand Up @@ -327,7 +296,6 @@ class AppBarTheme with Diagnosticable {
return false;
}
return other is AppBarTheme
&& other.brightness == brightness
&& other.backgroundColor == backgroundColor
&& other.foregroundColor == foregroundColor
&& other.elevation == elevation
Expand All @@ -349,7 +317,6 @@ class AppBarTheme with Diagnosticable {
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<Brightness>('brightness', brightness, defaultValue: null));
properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null));
properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null));
properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null));
Expand Down
5 changes: 4 additions & 1 deletion packages/flutter/lib/src/material/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

import 'app_bar.dart';
Expand Down Expand Up @@ -231,7 +232,9 @@ abstract class SearchDelegate<T> {
final ColorScheme colorScheme = theme.colorScheme;
return theme.copyWith(
appBarTheme: AppBarTheme(
brightness: colorScheme.brightness,
systemOverlayStyle: colorScheme.brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark,
backgroundColor: colorScheme.brightness == Brightness.dark ? Colors.grey[900] : Colors.white,
iconTheme: theme.primaryIconTheme.copyWith(color: Colors.grey),
titleTextStyle: theme.textTheme.titleLarge,
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/services/system_chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class SystemChrome {
/// page, consider calling when pushing/popping a new [PageRoute].
///
/// However, the [AppBar] widget automatically sets the system overlay style
/// based on its [AppBar.brightness], so configure that instead of calling
/// based on its [AppBar.systemOverlayStyle], so configure that instead of calling
/// this method directly. Likewise, do the same for [CupertinoNavigationBar]
/// via [CupertinoNavigationBar.backgroundColor].
///
Expand Down
11 changes: 4 additions & 7 deletions packages/flutter/test/material/app_bar_theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void main() {
final RichText actionIconText = _getAppBarIconRichText(tester);
final DefaultTextStyle text = _getAppBarText(tester);

expect(SystemChrome.latestStyle!.statusBarBrightness, appBarTheme.brightness);
expect(SystemChrome.latestStyle!.statusBarBrightness, Brightness.light);
expect(widget.color, appBarTheme.backgroundColor);
expect(widget.elevation, appBarTheme.elevation);
expect(widget.shadowColor, appBarTheme.shadowColor);
Expand Down Expand Up @@ -167,7 +167,6 @@ void main() {
home: Scaffold(
appBar: AppBar(
backgroundColor: color,
brightness: brightness,
systemOverlayStyle: systemOverlayStyle,
elevation: elevation,
shadowColor: shadowColor,
Expand Down Expand Up @@ -246,7 +245,7 @@ void main() {
final RichText actionIconText = _getAppBarIconRichText(tester);
final DefaultTextStyle text = _getAppBarText(tester);

expect(SystemChrome.latestStyle!.statusBarBrightness, appBarTheme.brightness);
expect(SystemChrome.latestStyle!.statusBarBrightness, Brightness.light);
expect(widget.color, appBarTheme.backgroundColor);
expect(widget.elevation, appBarTheme.elevation);
expect(widget.shadowColor, appBarTheme.shadowColor);
Expand Down Expand Up @@ -804,7 +803,6 @@ void main() {
testWidgets('AppBarTheme implements debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const AppBarTheme(
brightness: Brightness.dark,
backgroundColor: Color(0xff000001),
elevation: 8.0,
shadowColor: Color(0xff000002),
Expand All @@ -819,7 +817,6 @@ void main() {
.toList();

expect(description, <String>[
'brightness: Brightness.dark',
'backgroundColor: Color(0xff000001)',
'elevation: 8.0',
'shadowColor: Color(0xff000002)',
Expand All @@ -837,7 +834,7 @@ void main() {
}

AppBarTheme _appBarTheme() {
const Brightness brightness = Brightness.light;
const SystemUiOverlayStyle systemOverlayStyle = SystemUiOverlayStyle.dark;
const Color backgroundColor = Colors.lightBlue;
const double elevation = 6.0;
const Color shadowColor = Colors.red;
Expand All @@ -846,7 +843,7 @@ AppBarTheme _appBarTheme() {
const IconThemeData actionsIconThemeData = IconThemeData(color: Colors.pink);
return const AppBarTheme(
actionsIconTheme: actionsIconThemeData,
brightness: brightness,
systemOverlayStyle: systemOverlayStyle,
backgroundColor: backgroundColor,
elevation: elevation,
shadowColor: shadowColor,
Expand Down

0 comments on commit f858302

Please sign in to comment.