Unverified Commit ba46cb8d authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Remove deprecated AppBar.color & AppBar.backwardsCompatibility (#120618)

parent 378668db
...@@ -172,10 +172,7 @@ class _PreferredAppBarSize extends Size { ...@@ -172,10 +172,7 @@ class _PreferredAppBarSize extends Size {
class AppBar extends StatefulWidget implements PreferredSizeWidget { class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// Creates a Material Design app bar. /// Creates a Material Design app bar.
/// ///
/// The arguments [primary], [toolbarOpacity], [bottomOpacity], /// If [elevation] is specified, it must be non-negative.
/// [backwardsCompatibility], and [automaticallyImplyLeading] must
/// not be null. Additionally, if [elevation] is specified, it must
/// be non-negative.
/// ///
/// Typically used in the [Scaffold.appBar] property. /// Typically used in the [Scaffold.appBar] property.
AppBar({ AppBar({
...@@ -204,11 +201,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -204,11 +201,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
this.bottomOpacity = 1.0, this.bottomOpacity = 1.0,
this.toolbarHeight, this.toolbarHeight,
this.leadingWidth, this.leadingWidth,
@Deprecated(
'This property is obsolete and is false by default. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
this.backwardsCompatibility,
this.toolbarTextStyle, this.toolbarTextStyle,
this.titleTextStyle, this.titleTextStyle,
this.systemOverlayStyle, this.systemOverlayStyle,
...@@ -651,27 +643,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -651,27 +643,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// {@endtemplate} /// {@endtemplate}
final double? leadingWidth; final double? leadingWidth;
/// {@template flutter.material.appbar.backwardsCompatibility}
/// This property is deprecated and is false by default.
///
/// If true, preserves the original defaults for the [backgroundColor],
/// [iconTheme], [actionsIconTheme] properties.
///
/// If this property is null, then [AppBarTheme.backwardsCompatibility] of
/// [ThemeData.appBarTheme] is used. If that is also null, the default
/// value is false.
///
/// This is a temporary property and it has been deprecated. App
/// developers are encouraged to opt into the new features by
/// leaving it default (false) and using the [foregroundColor] and
/// [systemOverlayStyle] properties as needed.
/// {@endtemplate}
@Deprecated(
'This property is obsolete and is false by default. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
final bool? backwardsCompatibility;
/// {@template flutter.material.appbar.toolbarTextStyle} /// {@template flutter.material.appbar.toolbarTextStyle}
/// The default text style for the AppBar's [leading], and /// The default text style for the AppBar's [leading], and
/// [actions] widgets, but not its [title]. /// [actions] widgets, but not its [title].
...@@ -710,8 +681,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -710,8 +681,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
/// {@template flutter.material.appbar.systemOverlayStyle} /// {@template flutter.material.appbar.systemOverlayStyle}
/// Specifies the style to use for the system overlays that overlap the AppBar. /// Specifies the style to use for the system overlays that overlap the AppBar.
/// ///
/// This property is only used if [backwardsCompatibility] is false (the default).
///
/// If this property is null, then [AppBarTheme.systemOverlayStyle] of /// If this property is null, then [AppBarTheme.systemOverlayStyle] of
/// [ThemeData.appBarTheme] is used. If that is also null, an appropriate /// [ThemeData.appBarTheme] is used. If that is also null, an appropriate
/// [SystemUiOverlayStyle] is calculated based on the [backgroundColor]. /// [SystemUiOverlayStyle] is calculated based on the [backgroundColor].
...@@ -862,13 +831,8 @@ class _AppBarState extends State<AppBar> { ...@@ -862,13 +831,8 @@ class _AppBarState extends State<AppBar> {
final bool useCloseButton = parentRoute is PageRoute<dynamic> && parentRoute.fullscreenDialog; final bool useCloseButton = parentRoute is PageRoute<dynamic> && parentRoute.fullscreenDialog;
final double toolbarHeight = widget.toolbarHeight ?? appBarTheme.toolbarHeight ?? kToolbarHeight; final double toolbarHeight = widget.toolbarHeight ?? appBarTheme.toolbarHeight ?? kToolbarHeight;
final bool backwardsCompatibility = widget.backwardsCompatibility ?? appBarTheme.backwardsCompatibility ?? false;
final Color backgroundColor = backwardsCompatibility final Color backgroundColor = _resolveColor(
? widget.backgroundColor
?? appBarTheme.backgroundColor
?? theme.primaryColor
: _resolveColor(
states, states,
widget.backgroundColor, widget.backgroundColor,
appBarTheme.backgroundColor, appBarTheme.backgroundColor,
...@@ -890,11 +854,7 @@ class _AppBarState extends State<AppBar> { ...@@ -890,11 +854,7 @@ class _AppBarState extends State<AppBar> {
?? elevation ?? elevation
: elevation; : elevation;
IconThemeData overallIconTheme = backwardsCompatibility IconThemeData overallIconTheme = widget.iconTheme
? widget.iconTheme
?? appBarTheme.iconTheme
?? theme.primaryIconTheme
: widget.iconTheme
?? appBarTheme.iconTheme ?? appBarTheme.iconTheme
?? defaults.iconTheme!.copyWith(color: foregroundColor); ?? defaults.iconTheme!.copyWith(color: foregroundColor);
...@@ -907,19 +867,11 @@ class _AppBarState extends State<AppBar> { ...@@ -907,19 +867,11 @@ class _AppBarState extends State<AppBar> {
?? defaults.actionsIconTheme?.copyWith(color: actionForegroundColor) ?? defaults.actionsIconTheme?.copyWith(color: actionForegroundColor)
?? overallIconTheme; ?? overallIconTheme;
TextStyle? toolbarTextStyle = backwardsCompatibility TextStyle? toolbarTextStyle = widget.toolbarTextStyle
? widget.toolbarTextStyle
?? appBarTheme.toolbarTextStyle
?? theme.primaryTextTheme.bodyMedium
: widget.toolbarTextStyle
?? appBarTheme.toolbarTextStyle ?? appBarTheme.toolbarTextStyle
?? defaults.toolbarTextStyle?.copyWith(color: foregroundColor); ?? defaults.toolbarTextStyle?.copyWith(color: foregroundColor);
TextStyle? titleTextStyle = backwardsCompatibility TextStyle? titleTextStyle = widget.titleTextStyle
? widget.titleTextStyle
?? appBarTheme.titleTextStyle
?? theme.primaryTextTheme.titleLarge
: widget.titleTextStyle
?? appBarTheme.titleTextStyle ?? appBarTheme.titleTextStyle
?? defaults.titleTextStyle?.copyWith(color: foregroundColor); ?? defaults.titleTextStyle?.copyWith(color: foregroundColor);
...@@ -1173,11 +1125,7 @@ class _AppBarState extends State<AppBar> { ...@@ -1173,11 +1125,7 @@ class _AppBarState extends State<AppBar> {
); );
} }
final SystemUiOverlayStyle overlayStyle = backwardsCompatibility final SystemUiOverlayStyle overlayStyle = widget.systemOverlayStyle
? widget.systemOverlayStyle
?? appBarTheme.systemOverlayStyle
?? _systemOverlayStyleForBrightness(ThemeData.estimateBrightnessForColor(backgroundColor))
: widget.systemOverlayStyle
?? appBarTheme.systemOverlayStyle ?? appBarTheme.systemOverlayStyle
?? defaults.systemOverlayStyle ?? defaults.systemOverlayStyle
?? _systemOverlayStyleForBrightness( ?? _systemOverlayStyleForBrightness(
...@@ -1247,7 +1195,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -1247,7 +1195,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
required this.shape, required this.shape,
required this.toolbarHeight, required this.toolbarHeight,
required this.leadingWidth, required this.leadingWidth,
required this.backwardsCompatibility,
required this.toolbarTextStyle, required this.toolbarTextStyle,
required this.titleTextStyle, required this.titleTextStyle,
required this.systemOverlayStyle, required this.systemOverlayStyle,
...@@ -1282,7 +1229,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -1282,7 +1229,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
final ShapeBorder? shape; final ShapeBorder? shape;
final double? toolbarHeight; final double? toolbarHeight;
final double? leadingWidth; final double? leadingWidth;
final bool? backwardsCompatibility;
final TextStyle? toolbarTextStyle; final TextStyle? toolbarTextStyle;
final TextStyle? titleTextStyle; final TextStyle? titleTextStyle;
final SystemUiOverlayStyle? systemOverlayStyle; final SystemUiOverlayStyle? systemOverlayStyle;
...@@ -1354,7 +1300,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -1354,7 +1300,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
bottomOpacity: pinned ? 1.0 : clampDouble(visibleMainHeight / _bottomHeight, 0.0, 1.0), bottomOpacity: pinned ? 1.0 : clampDouble(visibleMainHeight / _bottomHeight, 0.0, 1.0),
toolbarHeight: toolbarHeight, toolbarHeight: toolbarHeight,
leadingWidth: leadingWidth, leadingWidth: leadingWidth,
backwardsCompatibility: backwardsCompatibility,
toolbarTextStyle: toolbarTextStyle, toolbarTextStyle: toolbarTextStyle,
titleTextStyle: titleTextStyle, titleTextStyle: titleTextStyle,
systemOverlayStyle: systemOverlayStyle, systemOverlayStyle: systemOverlayStyle,
...@@ -1393,7 +1338,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -1393,7 +1338,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|| forceElevated != oldDelegate.forceElevated || forceElevated != oldDelegate.forceElevated
|| toolbarHeight != oldDelegate.toolbarHeight || toolbarHeight != oldDelegate.toolbarHeight
|| leadingWidth != oldDelegate.leadingWidth || leadingWidth != oldDelegate.leadingWidth
|| backwardsCompatibility != oldDelegate.backwardsCompatibility
|| toolbarTextStyle != oldDelegate.toolbarTextStyle || toolbarTextStyle != oldDelegate.toolbarTextStyle
|| titleTextStyle != oldDelegate.titleTextStyle || titleTextStyle != oldDelegate.titleTextStyle
|| systemOverlayStyle != oldDelegate.systemOverlayStyle || systemOverlayStyle != oldDelegate.systemOverlayStyle
...@@ -1528,11 +1472,6 @@ class SliverAppBar extends StatefulWidget { ...@@ -1528,11 +1472,6 @@ class SliverAppBar extends StatefulWidget {
this.shape, this.shape,
this.toolbarHeight = kToolbarHeight, this.toolbarHeight = kToolbarHeight,
this.leadingWidth, this.leadingWidth,
@Deprecated(
'This property is obsolete and is false by default. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
this.backwardsCompatibility,
this.toolbarTextStyle, this.toolbarTextStyle,
this.titleTextStyle, this.titleTextStyle,
this.systemOverlayStyle, this.systemOverlayStyle,
...@@ -1977,15 +1916,6 @@ class SliverAppBar extends StatefulWidget { ...@@ -1977,15 +1916,6 @@ class SliverAppBar extends StatefulWidget {
/// This property is used to configure an [AppBar]. /// This property is used to configure an [AppBar].
final double? leadingWidth; final double? leadingWidth;
/// {@macro flutter.material.appbar.backwardsCompatibility}
///
/// This property is used to configure an [AppBar].
@Deprecated(
'This property is obsolete and is false by default. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
final bool? backwardsCompatibility;
/// {@macro flutter.material.appbar.toolbarTextStyle} /// {@macro flutter.material.appbar.toolbarTextStyle}
/// ///
/// This property is used to configure an [AppBar]. /// This property is used to configure an [AppBar].
...@@ -2108,7 +2038,6 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix ...@@ -2108,7 +2038,6 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix
showOnScreenConfiguration: _showOnScreenConfiguration, showOnScreenConfiguration: _showOnScreenConfiguration,
toolbarHeight: widget.toolbarHeight, toolbarHeight: widget.toolbarHeight,
leadingWidth: widget.leadingWidth, leadingWidth: widget.leadingWidth,
backwardsCompatibility: widget.backwardsCompatibility,
toolbarTextStyle: widget.toolbarTextStyle, toolbarTextStyle: widget.toolbarTextStyle,
titleTextStyle: widget.titleTextStyle, titleTextStyle: widget.titleTextStyle,
systemOverlayStyle: widget.systemOverlayStyle, systemOverlayStyle: widget.systemOverlayStyle,
......
...@@ -43,35 +43,12 @@ class AppBarTheme with Diagnosticable { ...@@ -43,35 +43,12 @@ class AppBarTheme with Diagnosticable {
this.toolbarTextStyle, this.toolbarTextStyle,
this.titleTextStyle, this.titleTextStyle,
this.systemOverlayStyle, this.systemOverlayStyle,
@Deprecated(
'This property is obsolete and is false by default. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
this.backwardsCompatibility,
}) : assert( }) : assert(
color == null || backgroundColor == null, color == null || backgroundColor == null,
'The color and backgroundColor parameters mean the same thing. Only specify one.', 'The color and backgroundColor parameters mean the same thing. Only specify one.',
), ),
backgroundColor = backgroundColor ?? color; backgroundColor = backgroundColor ?? color;
/// This property is deprecated, please use [backgroundColor] instead.
///
/// Obsolete property that overrides the default value of
/// [AppBar.backgroundColor] in all descendant [AppBar] widgets.
///
/// See also:
///
/// * [backgroundColor], which serves this same purpose
/// as this property, but has a name that's consistent with
/// [AppBar.backgroundColor].
/// * [AppBar.backwardsCompatibility], which forces [AppBar] to depend
/// on this obsolete property.
@Deprecated(
'This property is no longer used, please use backgroundColor instead. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
Color? get color => backgroundColor;
/// Overrides the default value of [AppBar.backgroundColor] in all /// Overrides the default value of [AppBar.backgroundColor] in all
/// descendant [AppBar] widgets. /// descendant [AppBar] widgets.
/// ///
...@@ -154,9 +131,6 @@ class AppBarTheme with Diagnosticable { ...@@ -154,9 +131,6 @@ class AppBarTheme with Diagnosticable {
/// Overrides the default value of the obsolete [AppBar.toolbarTextStyle] /// Overrides the default value of the obsolete [AppBar.toolbarTextStyle]
/// property in all descendant [AppBar] widgets. /// property in all descendant [AppBar] widgets.
/// ///
/// If this property is specified, then [backwardsCompatibility]
/// should be false (the default).
///
/// See also: /// See also:
/// ///
/// * [titleTextStyle], which overrides the default of [AppBar.titleTextStyle] /// * [titleTextStyle], which overrides the default of [AppBar.titleTextStyle]
...@@ -166,9 +140,6 @@ class AppBarTheme with Diagnosticable { ...@@ -166,9 +140,6 @@ class AppBarTheme with Diagnosticable {
/// Overrides the default value of [AppBar.titleTextStyle] /// Overrides the default value of [AppBar.titleTextStyle]
/// property in all descendant [AppBar] widgets. /// property in all descendant [AppBar] widgets.
/// ///
/// If this property is specified, then [backwardsCompatibility]
/// should be false (the default).
///
/// See also: /// See also:
/// ///
/// * [toolbarTextStyle], which overrides the default of [AppBar.toolbarTextStyle] /// * [toolbarTextStyle], which overrides the default of [AppBar.toolbarTextStyle]
...@@ -179,14 +150,6 @@ class AppBarTheme with Diagnosticable { ...@@ -179,14 +150,6 @@ class AppBarTheme with Diagnosticable {
/// property in all descendant [AppBar] widgets. /// property in all descendant [AppBar] widgets.
final SystemUiOverlayStyle? systemOverlayStyle; final SystemUiOverlayStyle? systemOverlayStyle;
/// Overrides the default value of [AppBar.backwardsCompatibility]
/// property in all descendant [AppBar] widgets.
@Deprecated(
'This property is obsolete and is false by default. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
final bool? backwardsCompatibility;
/// Creates a copy of this object with the given fields replaced with the /// Creates a copy of this object with the given fields replaced with the
/// new values. /// new values.
AppBarTheme copyWith({ AppBarTheme copyWith({
...@@ -206,11 +169,6 @@ class AppBarTheme with Diagnosticable { ...@@ -206,11 +169,6 @@ class AppBarTheme with Diagnosticable {
TextStyle? toolbarTextStyle, TextStyle? toolbarTextStyle,
TextStyle? titleTextStyle, TextStyle? titleTextStyle,
SystemUiOverlayStyle? systemOverlayStyle, SystemUiOverlayStyle? systemOverlayStyle,
@Deprecated(
'This property is obsolete and is false by default. '
'This feature was deprecated after v2.4.0-0.0.pre.',
)
bool? backwardsCompatibility,
}) { }) {
assert( assert(
color == null || backgroundColor == null, color == null || backgroundColor == null,
...@@ -232,7 +190,6 @@ class AppBarTheme with Diagnosticable { ...@@ -232,7 +190,6 @@ class AppBarTheme with Diagnosticable {
toolbarTextStyle: toolbarTextStyle ?? this.toolbarTextStyle, toolbarTextStyle: toolbarTextStyle ?? this.toolbarTextStyle,
titleTextStyle: titleTextStyle ?? this.titleTextStyle, titleTextStyle: titleTextStyle ?? this.titleTextStyle,
systemOverlayStyle: systemOverlayStyle ?? this.systemOverlayStyle, systemOverlayStyle: systemOverlayStyle ?? this.systemOverlayStyle,
backwardsCompatibility: backwardsCompatibility ?? this.backwardsCompatibility,
); );
} }
...@@ -263,7 +220,6 @@ class AppBarTheme with Diagnosticable { ...@@ -263,7 +220,6 @@ class AppBarTheme with Diagnosticable {
toolbarTextStyle: TextStyle.lerp(a?.toolbarTextStyle, b?.toolbarTextStyle, t), toolbarTextStyle: TextStyle.lerp(a?.toolbarTextStyle, b?.toolbarTextStyle, t),
titleTextStyle: TextStyle.lerp(a?.titleTextStyle, b?.titleTextStyle, t), titleTextStyle: TextStyle.lerp(a?.titleTextStyle, b?.titleTextStyle, t),
systemOverlayStyle: t < 0.5 ? a?.systemOverlayStyle : b?.systemOverlayStyle, systemOverlayStyle: t < 0.5 ? a?.systemOverlayStyle : b?.systemOverlayStyle,
backwardsCompatibility: t < 0.5 ? a?.backwardsCompatibility : b?.backwardsCompatibility,
); );
} }
...@@ -284,7 +240,6 @@ class AppBarTheme with Diagnosticable { ...@@ -284,7 +240,6 @@ class AppBarTheme with Diagnosticable {
toolbarTextStyle, toolbarTextStyle,
titleTextStyle, titleTextStyle,
systemOverlayStyle, systemOverlayStyle,
backwardsCompatibility,
); );
@override @override
...@@ -310,8 +265,7 @@ class AppBarTheme with Diagnosticable { ...@@ -310,8 +265,7 @@ class AppBarTheme with Diagnosticable {
&& other.toolbarHeight == toolbarHeight && other.toolbarHeight == toolbarHeight
&& other.toolbarTextStyle == toolbarTextStyle && other.toolbarTextStyle == toolbarTextStyle
&& other.titleTextStyle == titleTextStyle && other.titleTextStyle == titleTextStyle
&& other.systemOverlayStyle == systemOverlayStyle && other.systemOverlayStyle == systemOverlayStyle;
&& other.backwardsCompatibility == backwardsCompatibility;
} }
@override @override
...@@ -331,6 +285,5 @@ class AppBarTheme with Diagnosticable { ...@@ -331,6 +285,5 @@ class AppBarTheme with Diagnosticable {
properties.add(DiagnosticsProperty<double>('toolbarHeight', toolbarHeight, defaultValue: null)); properties.add(DiagnosticsProperty<double>('toolbarHeight', toolbarHeight, defaultValue: null));
properties.add(DiagnosticsProperty<TextStyle>('toolbarTextStyle', toolbarTextStyle, defaultValue: null)); properties.add(DiagnosticsProperty<TextStyle>('toolbarTextStyle', toolbarTextStyle, defaultValue: null));
properties.add(DiagnosticsProperty<TextStyle>('titleTextStyle', titleTextStyle, defaultValue: null)); properties.add(DiagnosticsProperty<TextStyle>('titleTextStyle', titleTextStyle, defaultValue: null));
properties.add(DiagnosticsProperty<bool>('backwardsCompatibility', backwardsCompatibility, defaultValue: null));
} }
} }
...@@ -504,10 +504,10 @@ class SystemChrome { ...@@ -504,10 +504,10 @@ class SystemChrome {
/// system UI styles. For instance, to change the system UI style on a new /// system UI styles. For instance, to change the system UI style on a new
/// 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 /// The [AppBar] widget automatically sets the system overlay style based on
/// based on its [AppBar.systemOverlayStyle], so configure that instead of calling /// its [AppBar.systemOverlayStyle], so configure that instead of calling this
/// this method directly. Likewise, do the same for [CupertinoNavigationBar] /// method directly. Likewise, do the same for [CupertinoNavigationBar] via
/// via [CupertinoNavigationBar.backgroundColor]. /// [CupertinoNavigationBar.backgroundColor].
/// ///
/// If a particular style is not supported on the platform, selecting it will /// If a particular style is not supported on the platform, selecting it will
/// have no effect. /// have no effect.
......
...@@ -2509,15 +2509,13 @@ void main() { ...@@ -2509,15 +2509,13 @@ void main() {
}); });
testWidgets('Default status bar color', (WidgetTester tester) async { testWidgets('Default status bar color', (WidgetTester tester) async {
Future<void> pumpBoilerplate({required bool useMaterial3, required bool backwardsCompatibility}) async { Future<void> pumpBoilerplate({required bool useMaterial3}) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
key: GlobalKey(), key: GlobalKey(),
theme: ThemeData.light().copyWith( theme: ThemeData.light().copyWith(
useMaterial3: useMaterial3, useMaterial3: useMaterial3,
appBarTheme: AppBarTheme( appBarTheme: const AppBarTheme(),
backwardsCompatibility: backwardsCompatibility,
),
), ),
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
...@@ -2528,14 +2526,10 @@ void main() { ...@@ -2528,14 +2526,10 @@ void main() {
); );
} }
await pumpBoilerplate(useMaterial3: false, backwardsCompatibility: false); await pumpBoilerplate(useMaterial3: false);
expect(SystemChrome.latestStyle!.statusBarColor, null);
await pumpBoilerplate(useMaterial3: false, backwardsCompatibility: true);
expect(SystemChrome.latestStyle!.statusBarColor, null); expect(SystemChrome.latestStyle!.statusBarColor, null);
await pumpBoilerplate(useMaterial3: true, backwardsCompatibility: false); await pumpBoilerplate(useMaterial3: true);
expect(SystemChrome.latestStyle!.statusBarColor, Colors.transparent); expect(SystemChrome.latestStyle!.statusBarColor, Colors.transparent);
await pumpBoilerplate(useMaterial3: true, backwardsCompatibility: true);
expect(SystemChrome.latestStyle!.statusBarColor, null);
}); });
testWidgets('AppBar systemOverlayStyle is use to style status bar and navigation bar', (WidgetTester tester) async { testWidgets('AppBar systemOverlayStyle is use to style status bar and navigation bar', (WidgetTester tester) async {
...@@ -3376,53 +3370,6 @@ void main() { ...@@ -3376,53 +3370,6 @@ void main() {
}); });
}); });
testWidgets('AppBarTheme.backwardsCompatibility', (WidgetTester tester) async {
const Color foregroundColor = Color(0xff00ff00);
final Key leadingIconKey = UniqueKey();
final Key actionIconKey = UniqueKey();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.light().copyWith(
useMaterial3: false,
appBarTheme: const AppBarTheme(
backwardsCompatibility: false,
),
),
home: Scaffold(
appBar: AppBar(
foregroundColor: foregroundColor, // only applies if backwardsCompatibility is false
leading: Icon(Icons.add_circle, key: leadingIconKey),
title: const Text('title'),
actions: <Widget>[Icon(Icons.ac_unit, key: actionIconKey), const Text('action')],
),
),
),
);
final TextStyle titleTextStyle = tester.widget<DefaultTextStyle>(
find.ancestor(of: find.text('title'), matching: find.byType(DefaultTextStyle)).first,
).style;
expect(titleTextStyle.color, foregroundColor);
final IconThemeData leadingIconTheme = tester.widget<IconTheme>(
find.ancestor(of: find.byKey(leadingIconKey), matching: find.byType(IconTheme)).first,
).data;
expect(leadingIconTheme.color, foregroundColor);
final IconThemeData actionIconTheme = tester.widget<IconTheme>(
find.ancestor(of: find.byKey(actionIconKey), matching: find.byType(IconTheme)).first,
).data;
expect(actionIconTheme.color, foregroundColor);
// Test icon color
Color? leadingIconColor() => iconStyle(tester, Icons.add_circle)?.color;
Color? actionIconColor() => iconStyle(tester, Icons.ac_unit)?.color;
expect(leadingIconColor(), foregroundColor);
expect(actionIconColor(), foregroundColor);
});
group('MaterialStateColor scrolledUnder', () { group('MaterialStateColor scrolledUnder', () {
const double collapsedHeight = kToolbarHeight; const double collapsedHeight = kToolbarHeight;
const double expandedHeight = 200.0; const double expandedHeight = 200.0;
......
...@@ -101,51 +101,6 @@ void main() { ...@@ -101,51 +101,6 @@ void main() {
expect(tester.getSize(find.byType(AppBar)).width, 800); expect(tester.getSize(find.byType(AppBar)).width, 800);
}); });
testWidgets('SliverAppBar allows AppBar to determine backwardsCompatibility', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/77016
const AppBarTheme appBarTheme = AppBarTheme(
backwardsCompatibility: false,
backgroundColor: Colors.lightBlue,
foregroundColor: Colors.black,
);
Widget buildWithBackwardsCompatibility([bool? enabled]) => MaterialApp(
theme: ThemeData(appBarTheme: appBarTheme),
home: Scaffold(body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: const Text('App Bar Title'),
backwardsCompatibility: enabled,
actions: <Widget>[
IconButton(icon: const Icon(Icons.share), onPressed: () { }),
],
),
],
)),
);
// Backwards compatibility enabled, AppBar should be built with true.
await tester.pumpWidget(buildWithBackwardsCompatibility(true));
AppBar appBar = tester.widget<AppBar>(find.byType(AppBar));
expect(appBar.backwardsCompatibility, true);
// Backwards compatibility disabled, AppBar should be built with false.
await tester.pumpWidget(buildWithBackwardsCompatibility(false));
appBar = tester.widget<AppBar>(find.byType(AppBar));
expect(appBar.backwardsCompatibility, false);
// Backwards compatibility unspecified, AppBar should be built with null.
await tester.pumpWidget(buildWithBackwardsCompatibility());
appBar = tester.widget<AppBar>(find.byType(AppBar));
expect(appBar.backwardsCompatibility, null);
// AppBar should use the backwardsCompatibility of AppBarTheme.
// Since backwardsCompatibility is false, the text color should match the
// foreground color of the AppBarTheme.
final DefaultTextStyle text = _getAppBarText(tester);
expect(text.style.color, appBarTheme.foregroundColor);
});
testWidgets('AppBar widget properties take priority over theme', (WidgetTester tester) async { testWidgets('AppBar widget properties take priority over theme', (WidgetTester tester) async {
const Brightness brightness = Brightness.dark; const Brightness brightness = Brightness.dark;
const SystemUiOverlayStyle systemOverlayStyle = SystemUiOverlayStyle.light; const SystemUiOverlayStyle systemOverlayStyle = SystemUiOverlayStyle.light;
......
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