Unverified Commit f858302a authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Remove `brightness` from `AppBar`/`SliverAppBar`/`AppBarTheme`/`AppBarTheme.copyWith` (#120575)

parent 73afc7ba
...@@ -194,11 +194,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -194,11 +194,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
this.shape, this.shape,
this.backgroundColor, this.backgroundColor,
this.foregroundColor, 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.iconTheme,
this.actionsIconTheme, this.actionsIconTheme,
this.primary = true, this.primary = true,
...@@ -499,7 +494,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -499,7 +494,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// If null, then the [AppBarTheme.backgroundColor] is used. If that value is also /// 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 /// null, then [AppBar] uses the overall theme's [ColorScheme.primary] if the
/// overall theme's brightness is [Brightness.light], and [ColorScheme.surface] /// 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 /// If this color is a [MaterialStateColor] it will be resolved against
/// [MaterialState.scrolledUnder] when the content of the app's /// [MaterialState.scrolledUnder] when the content of the app's
...@@ -525,7 +520,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -525,7 +520,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// value is also null, then [AppBar] uses the overall theme's /// value is also null, then [AppBar] uses the overall theme's
/// [ColorScheme.onPrimary] if the overall theme's brightness is /// [ColorScheme.onPrimary] if the overall theme's brightness is
/// [Brightness.light], and [ColorScheme.onSurface] if the overall /// [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 /// This color is used to configure [DefaultTextStyle] that contains
/// the toolbar's children, and the default [IconTheme] widgets that /// the toolbar's children, and the default [IconTheme] widgets that
...@@ -543,38 +538,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -543,38 +538,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// is light or dark. /// is light or dark.
final Color? foregroundColor; 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} /// {@template flutter.material.appbar.iconTheme}
/// The color, opacity, and size to use for toolbar icons. /// The color, opacity, and size to use for toolbar icons.
/// ///
...@@ -692,8 +655,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -692,8 +655,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// This property is deprecated and is false by default. /// This property is deprecated and is false by default.
/// ///
/// If true, preserves the original defaults for the [backgroundColor], /// If true, preserves the original defaults for the [backgroundColor],
/// [iconTheme], [actionsIconTheme] properties, and the original use of /// [iconTheme], [actionsIconTheme] properties.
/// the [brightness] property.
/// ///
/// If this property is null, then [AppBarTheme.backwardsCompatibility] of /// If this property is null, then [AppBarTheme.backwardsCompatibility] of
/// [ThemeData.appBarTheme] is used. If that is also null, the default /// [ThemeData.appBarTheme] is used. If that is also null, the default
...@@ -1212,11 +1174,9 @@ class _AppBarState extends State<AppBar> { ...@@ -1212,11 +1174,9 @@ class _AppBarState extends State<AppBar> {
} }
final SystemUiOverlayStyle overlayStyle = backwardsCompatibility final SystemUiOverlayStyle overlayStyle = backwardsCompatibility
? _systemOverlayStyleForBrightness( ? widget.systemOverlayStyle
widget.brightness ?? appBarTheme.systemOverlayStyle
?? appBarTheme.brightness ?? _systemOverlayStyleForBrightness(ThemeData.estimateBrightnessForColor(backgroundColor))
?? ThemeData.estimateBrightnessForColor(backgroundColor),
)
: widget.systemOverlayStyle : widget.systemOverlayStyle
?? appBarTheme.systemOverlayStyle ?? appBarTheme.systemOverlayStyle
?? defaults.systemOverlayStyle ?? defaults.systemOverlayStyle
...@@ -1269,7 +1229,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -1269,7 +1229,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
required this.forceElevated, required this.forceElevated,
required this.backgroundColor, required this.backgroundColor,
required this.foregroundColor, required this.foregroundColor,
required this.brightness,
required this.iconTheme, required this.iconTheme,
required this.actionsIconTheme, required this.actionsIconTheme,
required this.primary, required this.primary,
...@@ -1309,7 +1268,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -1309,7 +1268,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
final bool forceElevated; final bool forceElevated;
final Color? backgroundColor; final Color? backgroundColor;
final Color? foregroundColor; final Color? foregroundColor;
final Brightness? brightness;
final IconThemeData? iconTheme; final IconThemeData? iconTheme;
final IconThemeData? actionsIconTheme; final IconThemeData? actionsIconTheme;
final bool primary; final bool primary;
...@@ -1385,7 +1343,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -1385,7 +1343,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
surfaceTintColor: surfaceTintColor, surfaceTintColor: surfaceTintColor,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
foregroundColor: foregroundColor, foregroundColor: foregroundColor,
brightness: brightness,
iconTheme: iconTheme, iconTheme: iconTheme,
actionsIconTheme: actionsIconTheme, actionsIconTheme: actionsIconTheme,
primary: primary, primary: primary,
...@@ -1420,7 +1377,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -1420,7 +1377,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|| shadowColor != oldDelegate.shadowColor || shadowColor != oldDelegate.shadowColor
|| backgroundColor != oldDelegate.backgroundColor || backgroundColor != oldDelegate.backgroundColor
|| foregroundColor != oldDelegate.foregroundColor || foregroundColor != oldDelegate.foregroundColor
|| brightness != oldDelegate.brightness
|| iconTheme != oldDelegate.iconTheme || iconTheme != oldDelegate.iconTheme
|| actionsIconTheme != oldDelegate.actionsIconTheme || actionsIconTheme != oldDelegate.actionsIconTheme
|| primary != oldDelegate.primary || primary != oldDelegate.primary
...@@ -1555,11 +1511,6 @@ class SliverAppBar extends StatefulWidget { ...@@ -1555,11 +1511,6 @@ class SliverAppBar extends StatefulWidget {
this.forceElevated = false, this.forceElevated = false,
this.backgroundColor, this.backgroundColor,
this.foregroundColor, 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.iconTheme,
this.actionsIconTheme, this.actionsIconTheme,
this.primary = true, this.primary = true,
...@@ -1865,15 +1816,6 @@ class SliverAppBar extends StatefulWidget { ...@@ -1865,15 +1816,6 @@ class SliverAppBar extends StatefulWidget {
/// This property is used to configure an [AppBar]. /// This property is used to configure an [AppBar].
final Color? foregroundColor; 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} /// {@macro flutter.material.appbar.iconTheme}
/// ///
/// This property is used to configure an [AppBar]. /// This property is used to configure an [AppBar].
...@@ -2149,7 +2091,6 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix ...@@ -2149,7 +2091,6 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix
forceElevated: widget.forceElevated, forceElevated: widget.forceElevated,
backgroundColor: widget.backgroundColor, backgroundColor: widget.backgroundColor,
foregroundColor: widget.foregroundColor, foregroundColor: widget.foregroundColor,
brightness: widget.brightness,
iconTheme: widget.iconTheme, iconTheme: widget.iconTheme,
actionsIconTheme: widget.actionsIconTheme, actionsIconTheme: widget.actionsIconTheme,
primary: widget.primary, primary: widget.primary,
......
...@@ -27,11 +27,6 @@ import 'theme.dart'; ...@@ -27,11 +27,6 @@ import 'theme.dart';
class AppBarTheme with Diagnosticable { class AppBarTheme with Diagnosticable {
/// Creates a theme that can be used for [ThemeData.appBarTheme]. /// Creates a theme that can be used for [ThemeData.appBarTheme].
const 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? color,
Color? backgroundColor, Color? backgroundColor,
this.foregroundColor, this.foregroundColor,
...@@ -59,24 +54,6 @@ class AppBarTheme with Diagnosticable { ...@@ -59,24 +54,6 @@ class AppBarTheme with Diagnosticable {
), ),
backgroundColor = backgroundColor ?? color; 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. /// This property is deprecated, please use [backgroundColor] instead.
/// ///
/// Obsolete property that overrides the default value of /// Obsolete property that overrides the default value of
...@@ -214,11 +191,6 @@ class AppBarTheme with Diagnosticable { ...@@ -214,11 +191,6 @@ class AppBarTheme with Diagnosticable {
/// new values. /// new values.
AppBarTheme copyWith({ AppBarTheme copyWith({
IconThemeData? actionsIconTheme, 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? color,
Color? backgroundColor, Color? backgroundColor,
Color? foregroundColor, Color? foregroundColor,
...@@ -245,7 +217,6 @@ class AppBarTheme with Diagnosticable { ...@@ -245,7 +217,6 @@ class AppBarTheme with Diagnosticable {
'The color and backgroundColor parameters mean the same thing. Only specify one.', 'The color and backgroundColor parameters mean the same thing. Only specify one.',
); );
return AppBarTheme( return AppBarTheme(
brightness: brightness ?? this.brightness,
backgroundColor: backgroundColor ?? color ?? this.backgroundColor, backgroundColor: backgroundColor ?? color ?? this.backgroundColor,
foregroundColor: foregroundColor ?? this.foregroundColor, foregroundColor: foregroundColor ?? this.foregroundColor,
elevation: elevation ?? this.elevation, elevation: elevation ?? this.elevation,
...@@ -277,7 +248,6 @@ class AppBarTheme with Diagnosticable { ...@@ -277,7 +248,6 @@ class AppBarTheme with Diagnosticable {
/// {@macro dart.ui.shadow.lerp} /// {@macro dart.ui.shadow.lerp}
static AppBarTheme lerp(AppBarTheme? a, AppBarTheme? b, double t) { static AppBarTheme lerp(AppBarTheme? a, AppBarTheme? b, double t) {
return AppBarTheme( return AppBarTheme(
brightness: t < 0.5 ? a?.brightness : b?.brightness,
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t), foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t),
elevation: lerpDouble(a?.elevation, b?.elevation, t), elevation: lerpDouble(a?.elevation, b?.elevation, t),
...@@ -299,7 +269,6 @@ class AppBarTheme with Diagnosticable { ...@@ -299,7 +269,6 @@ class AppBarTheme with Diagnosticable {
@override @override
int get hashCode => Object.hash( int get hashCode => Object.hash(
brightness,
backgroundColor, backgroundColor,
foregroundColor, foregroundColor,
elevation, elevation,
...@@ -327,7 +296,6 @@ class AppBarTheme with Diagnosticable { ...@@ -327,7 +296,6 @@ class AppBarTheme with Diagnosticable {
return false; return false;
} }
return other is AppBarTheme return other is AppBarTheme
&& other.brightness == brightness
&& other.backgroundColor == backgroundColor && other.backgroundColor == backgroundColor
&& other.foregroundColor == foregroundColor && other.foregroundColor == foregroundColor
&& other.elevation == elevation && other.elevation == elevation
...@@ -349,7 +317,6 @@ class AppBarTheme with Diagnosticable { ...@@ -349,7 +317,6 @@ class AppBarTheme with Diagnosticable {
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<Brightness>('brightness', brightness, defaultValue: null));
properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null));
properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null)); properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null));
properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null)); properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null));
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'app_bar.dart'; import 'app_bar.dart';
...@@ -231,7 +232,9 @@ abstract class SearchDelegate<T> { ...@@ -231,7 +232,9 @@ abstract class SearchDelegate<T> {
final ColorScheme colorScheme = theme.colorScheme; final ColorScheme colorScheme = theme.colorScheme;
return theme.copyWith( return theme.copyWith(
appBarTheme: AppBarTheme( appBarTheme: AppBarTheme(
brightness: colorScheme.brightness, systemOverlayStyle: colorScheme.brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark,
backgroundColor: colorScheme.brightness == Brightness.dark ? Colors.grey[900] : Colors.white, backgroundColor: colorScheme.brightness == Brightness.dark ? Colors.grey[900] : Colors.white,
iconTheme: theme.primaryIconTheme.copyWith(color: Colors.grey), iconTheme: theme.primaryIconTheme.copyWith(color: Colors.grey),
titleTextStyle: theme.textTheme.titleLarge, titleTextStyle: theme.textTheme.titleLarge,
......
...@@ -505,7 +505,7 @@ class SystemChrome { ...@@ -505,7 +505,7 @@ class SystemChrome {
/// page, consider calling when pushing/popping a new [PageRoute]. /// page, consider calling when pushing/popping a new [PageRoute].
/// ///
/// However, the [AppBar] widget automatically sets the system overlay style /// 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] /// this method directly. Likewise, do the same for [CupertinoNavigationBar]
/// via [CupertinoNavigationBar.backgroundColor]. /// via [CupertinoNavigationBar.backgroundColor].
/// ///
......
...@@ -87,7 +87,7 @@ void main() { ...@@ -87,7 +87,7 @@ void main() {
final RichText actionIconText = _getAppBarIconRichText(tester); final RichText actionIconText = _getAppBarIconRichText(tester);
final DefaultTextStyle text = _getAppBarText(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.color, appBarTheme.backgroundColor);
expect(widget.elevation, appBarTheme.elevation); expect(widget.elevation, appBarTheme.elevation);
expect(widget.shadowColor, appBarTheme.shadowColor); expect(widget.shadowColor, appBarTheme.shadowColor);
...@@ -167,7 +167,6 @@ void main() { ...@@ -167,7 +167,6 @@ void main() {
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: color, backgroundColor: color,
brightness: brightness,
systemOverlayStyle: systemOverlayStyle, systemOverlayStyle: systemOverlayStyle,
elevation: elevation, elevation: elevation,
shadowColor: shadowColor, shadowColor: shadowColor,
...@@ -246,7 +245,7 @@ void main() { ...@@ -246,7 +245,7 @@ void main() {
final RichText actionIconText = _getAppBarIconRichText(tester); final RichText actionIconText = _getAppBarIconRichText(tester);
final DefaultTextStyle text = _getAppBarText(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.color, appBarTheme.backgroundColor);
expect(widget.elevation, appBarTheme.elevation); expect(widget.elevation, appBarTheme.elevation);
expect(widget.shadowColor, appBarTheme.shadowColor); expect(widget.shadowColor, appBarTheme.shadowColor);
...@@ -804,7 +803,6 @@ void main() { ...@@ -804,7 +803,6 @@ void main() {
testWidgets('AppBarTheme implements debugFillProperties', (WidgetTester tester) async { testWidgets('AppBarTheme implements debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const AppBarTheme( const AppBarTheme(
brightness: Brightness.dark,
backgroundColor: Color(0xff000001), backgroundColor: Color(0xff000001),
elevation: 8.0, elevation: 8.0,
shadowColor: Color(0xff000002), shadowColor: Color(0xff000002),
...@@ -819,7 +817,6 @@ void main() { ...@@ -819,7 +817,6 @@ void main() {
.toList(); .toList();
expect(description, <String>[ expect(description, <String>[
'brightness: Brightness.dark',
'backgroundColor: Color(0xff000001)', 'backgroundColor: Color(0xff000001)',
'elevation: 8.0', 'elevation: 8.0',
'shadowColor: Color(0xff000002)', 'shadowColor: Color(0xff000002)',
...@@ -837,7 +834,7 @@ void main() { ...@@ -837,7 +834,7 @@ void main() {
} }
AppBarTheme _appBarTheme() { AppBarTheme _appBarTheme() {
const Brightness brightness = Brightness.light; const SystemUiOverlayStyle systemOverlayStyle = SystemUiOverlayStyle.dark;
const Color backgroundColor = Colors.lightBlue; const Color backgroundColor = Colors.lightBlue;
const double elevation = 6.0; const double elevation = 6.0;
const Color shadowColor = Colors.red; const Color shadowColor = Colors.red;
...@@ -846,7 +843,7 @@ AppBarTheme _appBarTheme() { ...@@ -846,7 +843,7 @@ AppBarTheme _appBarTheme() {
const IconThemeData actionsIconThemeData = IconThemeData(color: Colors.pink); const IconThemeData actionsIconThemeData = IconThemeData(color: Colors.pink);
return const AppBarTheme( return const AppBarTheme(
actionsIconTheme: actionsIconThemeData, actionsIconTheme: actionsIconThemeData,
brightness: brightness, systemOverlayStyle: systemOverlayStyle,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
elevation: elevation, elevation: elevation,
shadowColor: shadowColor, shadowColor: shadowColor,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment