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 {
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,
......@@ -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
......@@ -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
......@@ -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.
///
......@@ -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
......@@ -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
......@@ -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,
......@@ -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;
......@@ -1385,7 +1343,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
surfaceTintColor: surfaceTintColor,
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
brightness: brightness,
iconTheme: iconTheme,
actionsIconTheme: actionsIconTheme,
primary: primary,
......@@ -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
......@@ -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,
......@@ -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].
......@@ -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,
......
......@@ -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,
......@@ -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
......@@ -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,
......@@ -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,
......@@ -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),
......@@ -299,7 +269,6 @@ class AppBarTheme with Diagnosticable {
@override
int get hashCode => Object.hash(
brightness,
backgroundColor,
foregroundColor,
elevation,
......@@ -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
......@@ -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));
......
......@@ -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';
......@@ -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,
......
......@@ -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].
///
......
......@@ -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);
......@@ -167,7 +167,6 @@ void main() {
home: Scaffold(
appBar: AppBar(
backgroundColor: color,
brightness: brightness,
systemOverlayStyle: systemOverlayStyle,
elevation: elevation,
shadowColor: shadowColor,
......@@ -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);
......@@ -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),
......@@ -819,7 +817,6 @@ void main() {
.toList();
expect(description, <String>[
'brightness: Brightness.dark',
'backgroundColor: Color(0xff000001)',
'elevation: 8.0',
'shadowColor: Color(0xff000002)',
......@@ -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;
......@@ -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,
......
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