Skip to content

Commit f858302

Browse files
authored
Remove brightness from AppBar/SliverAppBar/AppBarTheme/AppBarTheme.copyWith (#120575)
1 parent 73afc7b commit f858302

File tree

5 files changed

+15
-107
lines changed

5 files changed

+15
-107
lines changed

packages/flutter/lib/src/material/app_bar.dart

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
194194
this.shape,
195195
this.backgroundColor,
196196
this.foregroundColor,
197-
@Deprecated(
198-
'This property is no longer used, please use systemOverlayStyle instead. '
199-
'This feature was deprecated after v2.4.0-0.0.pre.',
200-
)
201-
this.brightness,
202197
this.iconTheme,
203198
this.actionsIconTheme,
204199
this.primary = true,
@@ -499,7 +494,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
499494
/// If null, then the [AppBarTheme.backgroundColor] is used. If that value is also
500495
/// null, then [AppBar] uses the overall theme's [ColorScheme.primary] if the
501496
/// overall theme's brightness is [Brightness.light], and [ColorScheme.surface]
502-
/// if the overall theme's [brightness] is [Brightness.dark].
497+
/// if the overall theme's brightness is [Brightness.dark].
503498
///
504499
/// If this color is a [MaterialStateColor] it will be resolved against
505500
/// [MaterialState.scrolledUnder] when the content of the app's
@@ -525,7 +520,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
525520
/// value is also null, then [AppBar] uses the overall theme's
526521
/// [ColorScheme.onPrimary] if the overall theme's brightness is
527522
/// [Brightness.light], and [ColorScheme.onSurface] if the overall
528-
/// theme's [brightness] is [Brightness.dark].
523+
/// theme's brightness is [Brightness.dark].
529524
///
530525
/// This color is used to configure [DefaultTextStyle] that contains
531526
/// the toolbar's children, and the default [IconTheme] widgets that
@@ -543,38 +538,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
543538
/// is light or dark.
544539
final Color? foregroundColor;
545540

546-
/// {@template flutter.material.appbar.brightness}
547-
/// This property is deprecated, please use [systemOverlayStyle] instead.
548-
///
549-
/// Determines the brightness of the [SystemUiOverlayStyle]: for
550-
/// [Brightness.dark], [SystemUiOverlayStyle.light] is used and for
551-
/// [Brightness.light], [SystemUiOverlayStyle.dark] is used.
552-
///
553-
/// If this value is null then [AppBarTheme.brightness] is used
554-
/// and if that's null then overall theme's brightness is used.
555-
///
556-
/// The AppBar is built within a `AnnotatedRegion<SystemUiOverlayStyle>`
557-
/// which causes [SystemChrome.setSystemUIOverlayStyle] to be called
558-
/// automatically. Apps should not enclose the AppBar with
559-
/// their own [AnnotatedRegion].
560-
/// {@endtemplate}
561-
///
562-
/// See also:
563-
///
564-
/// * [Theme.of], which returns the current overall Material theme as
565-
/// a [ThemeData].
566-
/// * [ThemeData.colorScheme], the thirteen colors that most Material widget
567-
/// default colors are based on.
568-
/// * [ColorScheme.brightness], which indicates if the overall [Theme]
569-
/// is light or dark.
570-
/// * [backwardsCompatibility], which forces AppBar to use this
571-
/// obsolete property.
572-
@Deprecated(
573-
'This property is no longer used, please use systemOverlayStyle instead. '
574-
'This feature was deprecated after v2.4.0-0.0.pre.',
575-
)
576-
final Brightness? brightness;
577-
578541
/// {@template flutter.material.appbar.iconTheme}
579542
/// The color, opacity, and size to use for toolbar icons.
580543
///
@@ -692,8 +655,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
692655
/// This property is deprecated and is false by default.
693656
///
694657
/// If true, preserves the original defaults for the [backgroundColor],
695-
/// [iconTheme], [actionsIconTheme] properties, and the original use of
696-
/// the [brightness] property.
658+
/// [iconTheme], [actionsIconTheme] properties.
697659
///
698660
/// If this property is null, then [AppBarTheme.backwardsCompatibility] of
699661
/// [ThemeData.appBarTheme] is used. If that is also null, the default
@@ -1212,11 +1174,9 @@ class _AppBarState extends State<AppBar> {
12121174
}
12131175

12141176
final SystemUiOverlayStyle overlayStyle = backwardsCompatibility
1215-
? _systemOverlayStyleForBrightness(
1216-
widget.brightness
1217-
?? appBarTheme.brightness
1218-
?? ThemeData.estimateBrightnessForColor(backgroundColor),
1219-
)
1177+
? widget.systemOverlayStyle
1178+
?? appBarTheme.systemOverlayStyle
1179+
?? _systemOverlayStyleForBrightness(ThemeData.estimateBrightnessForColor(backgroundColor))
12201180
: widget.systemOverlayStyle
12211181
?? appBarTheme.systemOverlayStyle
12221182
?? defaults.systemOverlayStyle
@@ -1269,7 +1229,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
12691229
required this.forceElevated,
12701230
required this.backgroundColor,
12711231
required this.foregroundColor,
1272-
required this.brightness,
12731232
required this.iconTheme,
12741233
required this.actionsIconTheme,
12751234
required this.primary,
@@ -1309,7 +1268,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
13091268
final bool forceElevated;
13101269
final Color? backgroundColor;
13111270
final Color? foregroundColor;
1312-
final Brightness? brightness;
13131271
final IconThemeData? iconTheme;
13141272
final IconThemeData? actionsIconTheme;
13151273
final bool primary;
@@ -1385,7 +1343,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
13851343
surfaceTintColor: surfaceTintColor,
13861344
backgroundColor: backgroundColor,
13871345
foregroundColor: foregroundColor,
1388-
brightness: brightness,
13891346
iconTheme: iconTheme,
13901347
actionsIconTheme: actionsIconTheme,
13911348
primary: primary,
@@ -1420,7 +1377,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
14201377
|| shadowColor != oldDelegate.shadowColor
14211378
|| backgroundColor != oldDelegate.backgroundColor
14221379
|| foregroundColor != oldDelegate.foregroundColor
1423-
|| brightness != oldDelegate.brightness
14241380
|| iconTheme != oldDelegate.iconTheme
14251381
|| actionsIconTheme != oldDelegate.actionsIconTheme
14261382
|| primary != oldDelegate.primary
@@ -1555,11 +1511,6 @@ class SliverAppBar extends StatefulWidget {
15551511
this.forceElevated = false,
15561512
this.backgroundColor,
15571513
this.foregroundColor,
1558-
@Deprecated(
1559-
'This property is no longer used, please use systemOverlayStyle instead. '
1560-
'This feature was deprecated after v2.4.0-0.0.pre.',
1561-
)
1562-
this.brightness,
15631514
this.iconTheme,
15641515
this.actionsIconTheme,
15651516
this.primary = true,
@@ -1865,15 +1816,6 @@ class SliverAppBar extends StatefulWidget {
18651816
/// This property is used to configure an [AppBar].
18661817
final Color? foregroundColor;
18671818

1868-
/// {@macro flutter.material.appbar.brightness}
1869-
///
1870-
/// This property is used to configure an [AppBar].
1871-
@Deprecated(
1872-
'This property is no longer used, please use systemOverlayStyle instead. '
1873-
'This feature was deprecated after v2.4.0-0.0.pre.',
1874-
)
1875-
final Brightness? brightness;
1876-
18771819
/// {@macro flutter.material.appbar.iconTheme}
18781820
///
18791821
/// This property is used to configure an [AppBar].
@@ -2149,7 +2091,6 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix
21492091
forceElevated: widget.forceElevated,
21502092
backgroundColor: widget.backgroundColor,
21512093
foregroundColor: widget.foregroundColor,
2152-
brightness: widget.brightness,
21532094
iconTheme: widget.iconTheme,
21542095
actionsIconTheme: widget.actionsIconTheme,
21552096
primary: widget.primary,

packages/flutter/lib/src/material/app_bar_theme.dart

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ import 'theme.dart';
2727
class AppBarTheme with Diagnosticable {
2828
/// Creates a theme that can be used for [ThemeData.appBarTheme].
2929
const AppBarTheme({
30-
@Deprecated(
31-
'This property is no longer used, please use systemOverlayStyle instead. '
32-
'This feature was deprecated after v2.4.0-0.0.pre.',
33-
)
34-
this.brightness,
3530
Color? color,
3631
Color? backgroundColor,
3732
this.foregroundColor,
@@ -59,24 +54,6 @@ class AppBarTheme with Diagnosticable {
5954
),
6055
backgroundColor = backgroundColor ?? color;
6156

62-
/// This property is deprecated, please use [systemOverlayStyle] instead.
63-
///
64-
/// Overrides the default value of the obsolete [AppBar.brightness]
65-
/// property which implicitly defines [AppBar.systemOverlayStyle] in
66-
/// all descendant [AppBar] widgets.
67-
///
68-
/// See also:
69-
///
70-
/// * [systemOverlayStyle], which overrides the default value of
71-
/// [AppBar.systemOverlayStyle] in all descendant [AppBar] widgets.
72-
/// * [AppBar.backwardsCompatibility], which forces [AppBar] to depend
73-
/// on this obsolete property.
74-
@Deprecated(
75-
'This property is no longer used, please use systemOverlayStyle instead. '
76-
'This feature was deprecated after v2.4.0-0.0.pre.',
77-
)
78-
final Brightness? brightness;
79-
8057
/// This property is deprecated, please use [backgroundColor] instead.
8158
///
8259
/// Obsolete property that overrides the default value of
@@ -214,11 +191,6 @@ class AppBarTheme with Diagnosticable {
214191
/// new values.
215192
AppBarTheme copyWith({
216193
IconThemeData? actionsIconTheme,
217-
@Deprecated(
218-
'This property is no longer used, please use systemOverlayStyle instead. '
219-
'This feature was deprecated after v2.4.0-0.0.pre.',
220-
)
221-
Brightness? brightness,
222194
Color? color,
223195
Color? backgroundColor,
224196
Color? foregroundColor,
@@ -245,7 +217,6 @@ class AppBarTheme with Diagnosticable {
245217
'The color and backgroundColor parameters mean the same thing. Only specify one.',
246218
);
247219
return AppBarTheme(
248-
brightness: brightness ?? this.brightness,
249220
backgroundColor: backgroundColor ?? color ?? this.backgroundColor,
250221
foregroundColor: foregroundColor ?? this.foregroundColor,
251222
elevation: elevation ?? this.elevation,
@@ -277,7 +248,6 @@ class AppBarTheme with Diagnosticable {
277248
/// {@macro dart.ui.shadow.lerp}
278249
static AppBarTheme lerp(AppBarTheme? a, AppBarTheme? b, double t) {
279250
return AppBarTheme(
280-
brightness: t < 0.5 ? a?.brightness : b?.brightness,
281251
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
282252
foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t),
283253
elevation: lerpDouble(a?.elevation, b?.elevation, t),
@@ -299,7 +269,6 @@ class AppBarTheme with Diagnosticable {
299269

300270
@override
301271
int get hashCode => Object.hash(
302-
brightness,
303272
backgroundColor,
304273
foregroundColor,
305274
elevation,
@@ -327,7 +296,6 @@ class AppBarTheme with Diagnosticable {
327296
return false;
328297
}
329298
return other is AppBarTheme
330-
&& other.brightness == brightness
331299
&& other.backgroundColor == backgroundColor
332300
&& other.foregroundColor == foregroundColor
333301
&& other.elevation == elevation
@@ -349,7 +317,6 @@ class AppBarTheme with Diagnosticable {
349317
@override
350318
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
351319
super.debugFillProperties(properties);
352-
properties.add(DiagnosticsProperty<Brightness>('brightness', brightness, defaultValue: null));
353320
properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null));
354321
properties.add(ColorProperty('foregroundColor', foregroundColor, defaultValue: null));
355322
properties.add(DiagnosticsProperty<double>('elevation', elevation, defaultValue: null));

packages/flutter/lib/src/material/search.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:flutter/services.dart';
56
import 'package:flutter/widgets.dart';
67

78
import 'app_bar.dart';
@@ -231,7 +232,9 @@ abstract class SearchDelegate<T> {
231232
final ColorScheme colorScheme = theme.colorScheme;
232233
return theme.copyWith(
233234
appBarTheme: AppBarTheme(
234-
brightness: colorScheme.brightness,
235+
systemOverlayStyle: colorScheme.brightness == Brightness.dark
236+
? SystemUiOverlayStyle.light
237+
: SystemUiOverlayStyle.dark,
235238
backgroundColor: colorScheme.brightness == Brightness.dark ? Colors.grey[900] : Colors.white,
236239
iconTheme: theme.primaryIconTheme.copyWith(color: Colors.grey),
237240
titleTextStyle: theme.textTheme.titleLarge,

packages/flutter/lib/src/services/system_chrome.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class SystemChrome {
505505
/// page, consider calling when pushing/popping a new [PageRoute].
506506
///
507507
/// However, the [AppBar] widget automatically sets the system overlay style
508-
/// based on its [AppBar.brightness], so configure that instead of calling
508+
/// based on its [AppBar.systemOverlayStyle], so configure that instead of calling
509509
/// this method directly. Likewise, do the same for [CupertinoNavigationBar]
510510
/// via [CupertinoNavigationBar.backgroundColor].
511511
///

packages/flutter/test/material/app_bar_theme_test.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void main() {
8787
final RichText actionIconText = _getAppBarIconRichText(tester);
8888
final DefaultTextStyle text = _getAppBarText(tester);
8989

90-
expect(SystemChrome.latestStyle!.statusBarBrightness, appBarTheme.brightness);
90+
expect(SystemChrome.latestStyle!.statusBarBrightness, Brightness.light);
9191
expect(widget.color, appBarTheme.backgroundColor);
9292
expect(widget.elevation, appBarTheme.elevation);
9393
expect(widget.shadowColor, appBarTheme.shadowColor);
@@ -167,7 +167,6 @@ void main() {
167167
home: Scaffold(
168168
appBar: AppBar(
169169
backgroundColor: color,
170-
brightness: brightness,
171170
systemOverlayStyle: systemOverlayStyle,
172171
elevation: elevation,
173172
shadowColor: shadowColor,
@@ -246,7 +245,7 @@ void main() {
246245
final RichText actionIconText = _getAppBarIconRichText(tester);
247246
final DefaultTextStyle text = _getAppBarText(tester);
248247

249-
expect(SystemChrome.latestStyle!.statusBarBrightness, appBarTheme.brightness);
248+
expect(SystemChrome.latestStyle!.statusBarBrightness, Brightness.light);
250249
expect(widget.color, appBarTheme.backgroundColor);
251250
expect(widget.elevation, appBarTheme.elevation);
252251
expect(widget.shadowColor, appBarTheme.shadowColor);
@@ -804,7 +803,6 @@ void main() {
804803
testWidgets('AppBarTheme implements debugFillProperties', (WidgetTester tester) async {
805804
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
806805
const AppBarTheme(
807-
brightness: Brightness.dark,
808806
backgroundColor: Color(0xff000001),
809807
elevation: 8.0,
810808
shadowColor: Color(0xff000002),
@@ -819,7 +817,6 @@ void main() {
819817
.toList();
820818

821819
expect(description, <String>[
822-
'brightness: Brightness.dark',
823820
'backgroundColor: Color(0xff000001)',
824821
'elevation: 8.0',
825822
'shadowColor: Color(0xff000002)',
@@ -837,7 +834,7 @@ void main() {
837834
}
838835

839836
AppBarTheme _appBarTheme() {
840-
const Brightness brightness = Brightness.light;
837+
const SystemUiOverlayStyle systemOverlayStyle = SystemUiOverlayStyle.dark;
841838
const Color backgroundColor = Colors.lightBlue;
842839
const double elevation = 6.0;
843840
const Color shadowColor = Colors.red;
@@ -846,7 +843,7 @@ AppBarTheme _appBarTheme() {
846843
const IconThemeData actionsIconThemeData = IconThemeData(color: Colors.pink);
847844
return const AppBarTheme(
848845
actionsIconTheme: actionsIconThemeData,
849-
brightness: brightness,
846+
systemOverlayStyle: systemOverlayStyle,
850847
backgroundColor: backgroundColor,
851848
elevation: elevation,
852849
shadowColor: shadowColor,

0 commit comments

Comments
 (0)