From 0082ff973eade4f090c0fd77310622b20817634a Mon Sep 17 00:00:00 2001 From: Aayan <50059339+Calamity210@users.noreply.github.com> Date: Mon, 27 Sep 2021 13:14:52 -0400 Subject: [PATCH] Material banner updates (#90380) --- packages/flutter/lib/src/material/banner.dart | 102 +++++++++++------ .../lib/src/material/banner_theme.dart | 14 +++ .../flutter/lib/src/material/scaffold.dart | 48 +++++--- .../flutter/test/material/banner_test.dart | 105 ++++++++++++++++-- .../test/material/banner_theme_test.dart | 80 ++++++------- .../test/material/inherited_theme_test.dart | 4 +- 6 files changed, 250 insertions(+), 103 deletions(-) diff --git a/packages/flutter/lib/src/material/banner.dart b/packages/flutter/lib/src/material/banner.dart index 90bffc27ec..6764a88ffa 100644 --- a/packages/flutter/lib/src/material/banner.dart +++ b/packages/flutter/lib/src/material/banner.dart @@ -6,12 +6,12 @@ import 'package:flutter/widgets.dart'; import 'banner_theme.dart'; import 'divider.dart'; +import 'material.dart'; import 'scaffold.dart'; import 'theme.dart'; const Duration _materialBannerTransitionDuration = Duration(milliseconds: 250); const Curve _materialBannerHeightCurve = Curves.fastOutSlowIn; -const Curve _materialBannerFadeOutCurve = Interval(0.72, 1.0, curve: Curves.fastOutSlowIn); /// Specify how a [MaterialBanner] was closed. /// @@ -84,12 +84,14 @@ class MaterialBanner extends StatefulWidget { /// Creates a [MaterialBanner]. /// /// The [actions], [content], and [forceActionsBelow] must be non-null. - /// The [actions].length must be greater than 0. + /// The [actions].length must be greater than 0. The [elevation] must be null or + /// non-negative. const MaterialBanner({ Key? key, required this.content, this.contentTextStyle, required this.actions, + this.elevation, this.leading, this.backgroundColor, this.padding, @@ -98,7 +100,8 @@ class MaterialBanner extends StatefulWidget { this.overflowAlignment = OverflowBarAlignment.end, this.animation, this.onVisible - }) : assert(content != null), + }) : assert(elevation == null || elevation >= 0.0), + assert(content != null), assert(actions != null), assert(forceActionsBelow != null), super(key: key); @@ -120,6 +123,18 @@ class MaterialBanner extends StatefulWidget { /// Typically this is a list of [TextButton] widgets. final List actions; + /// The z-coordinate at which to place the material banner. + /// + /// This controls the size of the shadow below the material banner. + /// + /// Defines the banner's [Material.elevation]. + /// + /// If this property is null, then [MaterialBannerThemeData.elevation] of + /// [ThemeData.bannerTheme] is used, if that is also null, the default value is 0. + /// If the elevation is 0, the [Scaffold]'s body will be pushed down by the + /// MaterialBanner when used with [ScaffoldMessenger]. + final double? elevation; + /// The (optional) leading widget of the [MaterialBanner]. /// /// Typically an [Icon] widget. @@ -188,6 +203,7 @@ class MaterialBanner extends StatefulWidget { content: content, contentTextStyle: contentTextStyle, actions: actions, + elevation: elevation, leading: leading, backgroundColor: backgroundColor, padding: padding, @@ -270,6 +286,7 @@ class _MaterialBannerState extends State { ), ); + final double elevation = widget.elevation ?? bannerTheme.elevation ?? 0.0; final Color backgroundColor = widget.backgroundColor ?? bannerTheme.backgroundColor ?? theme.colorScheme.surface; @@ -278,34 +295,40 @@ class _MaterialBannerState extends State { ?? theme.textTheme.bodyText2; Widget materialBanner = Container( - color: backgroundColor, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: padding, - child: Row( - children: [ - if (widget.leading != null) - Padding( - padding: leadingPadding, - child: widget.leading, + margin: EdgeInsets.only(bottom: elevation > 0 ? 10.0 : 0.0), + child: Material( + elevation: elevation, + color: backgroundColor, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: padding, + child: Row( + children: [ + if (widget.leading != null) + Padding( + padding: leadingPadding, + child: widget.leading, + ), + Expanded( + child: DefaultTextStyle( + style: textStyle!, + child: widget.content, + ), ), - Expanded( - child: DefaultTextStyle( - style: textStyle!, - child: widget.content, - ), - ), - if (isSingleRow) - buttonBar, - ], + if (isSingleRow) + buttonBar, + ], + ), ), - ), - if (!isSingleRow) - buttonBar, - const Divider(height: 0), - ], + if (!isSingleRow) + buttonBar, + + if (elevation == 0) + const Divider(height: 0), + ], + ), ), ); @@ -313,13 +336,20 @@ class _MaterialBannerState extends State { if (widget.animation == null) return materialBanner; - final CurvedAnimation heightAnimation = CurvedAnimation(parent: widget.animation!, curve: _materialBannerHeightCurve); - final CurvedAnimation fadeOutAnimation = CurvedAnimation( - parent: widget.animation!, - curve: _materialBannerFadeOutCurve, - reverseCurve: const Threshold(0.0), + materialBanner = SafeArea( + top: true, + child: materialBanner, ); + final CurvedAnimation heightAnimation = CurvedAnimation(parent: widget.animation!, curve: _materialBannerHeightCurve); + final Animation slideOutAnimation = Tween( + begin: const Offset(0.0, -1.0), + end: Offset.zero, + ).animate(CurvedAnimation( + parent: widget.animation!, + curve: const Threshold(0.0), + )); + materialBanner = Semantics( container: true, liveRegion: true, @@ -328,8 +358,8 @@ class _MaterialBannerState extends State { }, child: mediaQueryData.accessibleNavigation ? materialBanner - : FadeTransition( - opacity: fadeOutAnimation, + : SlideTransition( + position: slideOutAnimation, child: materialBanner, ), ); diff --git a/packages/flutter/lib/src/material/banner_theme.dart b/packages/flutter/lib/src/material/banner_theme.dart index 2d495a79fe..060b749ed0 100644 --- a/packages/flutter/lib/src/material/banner_theme.dart +++ b/packages/flutter/lib/src/material/banner_theme.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:ui' show lerpDouble; + import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; @@ -31,6 +33,7 @@ class MaterialBannerThemeData with Diagnosticable { const MaterialBannerThemeData({ this.backgroundColor, this.contentTextStyle, + this.elevation, this.padding, this.leadingPadding, }); @@ -42,6 +45,11 @@ class MaterialBannerThemeData with Diagnosticable { /// widget. final TextStyle? contentTextStyle; + /// Default value for [MaterialBanner.elevation]. + // + // If null, MaterialBanner uses a default of 0.0. + final double? elevation; + /// The amount of space by which to inset [MaterialBanner.content]. final EdgeInsetsGeometry? padding; @@ -53,12 +61,14 @@ class MaterialBannerThemeData with Diagnosticable { MaterialBannerThemeData copyWith({ Color? backgroundColor, TextStyle? contentTextStyle, + double? elevation, EdgeInsetsGeometry? padding, EdgeInsetsGeometry? leadingPadding, }) { return MaterialBannerThemeData( backgroundColor: backgroundColor ?? this.backgroundColor, contentTextStyle: contentTextStyle ?? this.contentTextStyle, + elevation: elevation ?? this.elevation, padding: padding ?? this.padding, leadingPadding: leadingPadding ?? this.leadingPadding, ); @@ -74,6 +84,7 @@ class MaterialBannerThemeData with Diagnosticable { return MaterialBannerThemeData( backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t), + elevation: lerpDouble(a?.elevation, b?.elevation, t), padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t), leadingPadding: EdgeInsetsGeometry.lerp(a?.leadingPadding, b?.leadingPadding, t), ); @@ -84,6 +95,7 @@ class MaterialBannerThemeData with Diagnosticable { return hashValues( backgroundColor, contentTextStyle, + elevation, padding, leadingPadding, ); @@ -98,6 +110,7 @@ class MaterialBannerThemeData with Diagnosticable { return other is MaterialBannerThemeData && other.backgroundColor == backgroundColor && other.contentTextStyle == contentTextStyle + && other.elevation == elevation && other.padding == padding && other.leadingPadding == leadingPadding; } @@ -107,6 +120,7 @@ class MaterialBannerThemeData with Diagnosticable { super.debugFillProperties(properties); properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); properties.add(DiagnosticsProperty('contentTextStyle', contentTextStyle, defaultValue: null)); + properties.add(DiagnosticsProperty('elevation', elevation, defaultValue: null)); properties.add(DiagnosticsProperty('padding', padding, defaultValue: null)); properties.add(DiagnosticsProperty('leadingPadding', leadingPadding, defaultValue: null)); } diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index bcb790774b..6e6a3a42c2 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -13,6 +13,7 @@ import 'package:flutter/widgets.dart'; import 'app_bar.dart'; import 'banner.dart'; +import 'banner_theme.dart'; import 'bottom_sheet.dart'; import 'colors.dart'; import 'curves.dart'; @@ -802,14 +803,18 @@ class _BodyBoxConstraints extends BoxConstraints { double maxHeight = double.infinity, required this.bottomWidgetsHeight, required this.appBarHeight, + required this.materialBannerHeight, }) : assert(bottomWidgetsHeight != null), assert(bottomWidgetsHeight >= 0), assert(appBarHeight != null), assert(appBarHeight >= 0), + assert(materialBannerHeight != null), + assert(materialBannerHeight >= 0), super(minWidth: minWidth, maxWidth: maxWidth, minHeight: minHeight, maxHeight: maxHeight); final double bottomWidgetsHeight; final double appBarHeight; + final double materialBannerHeight; // RenderObject.layout() will only short-circuit its call to its performLayout // method if the new layout constraints are not == to the current constraints. @@ -820,13 +825,14 @@ class _BodyBoxConstraints extends BoxConstraints { if (super != other) return false; return other is _BodyBoxConstraints + && other.materialBannerHeight == materialBannerHeight && other.bottomWidgetsHeight == bottomWidgetsHeight && other.appBarHeight == appBarHeight; } @override int get hashCode { - return hashValues(super.hashCode, bottomWidgetsHeight, appBarHeight); + return hashValues(super.hashCode, materialBannerHeight, bottomWidgetsHeight, appBarHeight); } } @@ -866,7 +872,8 @@ class _BodyBuilder extends StatelessWidget { : metrics.padding.bottom; final double top = extendBodyBehindAppBar - ? math.max(metrics.padding.top, bodyConstraints.appBarHeight) + ? math.max(metrics.padding.top, + bodyConstraints.appBarHeight + bodyConstraints.materialBannerHeight) : metrics.padding.top; return MediaQuery( @@ -898,6 +905,7 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { required this.snackBarWidth, required this.extendBody, required this.extendBodyBehindAppBar, + required this.extendBodyBehindMaterialBanner, }) : assert(minInsets != null), assert(textDirection != null), assert(geometryNotifier != null), @@ -921,6 +929,8 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { final bool isSnackBarFloating; final double? snackBarWidth; + final bool extendBodyBehindMaterialBanner; + @override void performLayout(Size size) { final BoxConstraints looseConstraints = BoxConstraints.loose(size); @@ -960,6 +970,17 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { positionChild(_ScaffoldSlot.persistentFooter, Offset(0.0, math.max(0.0, bottom - bottomWidgetsHeight))); } + Size materialBannerSize = Size.zero; + if (hasChild(_ScaffoldSlot.materialBanner)) { + materialBannerSize = layoutChild(_ScaffoldSlot.materialBanner, fullWidthConstraints); + positionChild(_ScaffoldSlot.materialBanner, Offset(0.0, appBarHeight)); + + // Push content down only if elevation is 0. + if (!extendBodyBehindMaterialBanner) { + contentTop += materialBannerSize.height; + } + } + // Set the content bottom to account for the greater of the height of any // bottom-anchored material widgets or of the keyboard or other // bottom-anchored system UI. @@ -977,6 +998,7 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { final BoxConstraints bodyConstraints = _BodyBoxConstraints( maxWidth: fullWidthConstraints.maxWidth, maxHeight: bodyMaxHeight, + materialBannerHeight: materialBannerSize.height, bottomWidgetsHeight: extendBody ? bottomWidgetsHeight : 0.0, appBarHeight: appBarHeight, ); @@ -1013,11 +1035,6 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { snackBarSize = layoutChild(_ScaffoldSlot.snackBar, fullWidthConstraints); } - Size materialBannerSize = Size.zero; - if (hasChild(_ScaffoldSlot.materialBanner)) { - materialBannerSize = layoutChild(_ScaffoldSlot.materialBanner, fullWidthConstraints); - } - if (hasChild(_ScaffoldSlot.bottomSheet)) { final BoxConstraints bottomSheetConstraints = BoxConstraints( maxWidth: fullWidthConstraints.maxWidth, @@ -1086,17 +1103,6 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate { positionChild(_ScaffoldSlot.snackBar, Offset(xOffset, snackBarYOffsetBase - snackBarSize.height)); } - if (hasChild(_ScaffoldSlot.materialBanner)) { - if (materialBannerSize == Size.zero) { - materialBannerSize = layoutChild( - _ScaffoldSlot.materialBanner, - fullWidthConstraints, - ); - } - - positionChild(_ScaffoldSlot.materialBanner, Offset(0.0, appBarHeight)); - } - if (hasChild(_ScaffoldSlot.statusBar)) { layoutChild(_ScaffoldSlot.statusBar, fullWidthConstraints.tighten(height: minInsets.top)); positionChild(_ScaffoldSlot.statusBar, Offset.zero); @@ -2927,8 +2933,13 @@ class ScaffoldState extends State with TickerProviderStateMixin, Resto ); } + bool extendBodyBehindMaterialBanner = false; // MaterialBanner set by ScaffoldMessenger if (_messengerMaterialBanner != null) { + final MaterialBannerThemeData bannerTheme = MaterialBannerTheme.of(context); + final double elevation = _messengerMaterialBanner?._widget.elevation ?? bannerTheme.elevation ?? 0.0; + extendBodyBehindMaterialBanner = elevation != 0.0; + _addIfNonNull( children, _messengerMaterialBanner?._widget, @@ -3070,6 +3081,7 @@ class ScaffoldState extends State with TickerProviderStateMixin, Resto previousFloatingActionButtonLocation: _previousFloatingActionButtonLocation!, textDirection: textDirection, isSnackBarFloating: isSnackBarFloating, + extendBodyBehindMaterialBanner: extendBodyBehindMaterialBanner, snackBarWidth: snackBarWidth, ), children: children, diff --git a/packages/flutter/test/material/banner_test.dart b/packages/flutter/test/material/banner_test.dart index 86bdacfcb2..d6f7464968 100644 --- a/packages/flutter/test/material/banner_test.dart +++ b/packages/flutter/test/material/banner_test.dart @@ -24,8 +24,8 @@ void main() { ), ); - final Container container = _getContainerFromBanner(tester); - expect(container.color, color); + final Material material = _getMaterialFromBanner(tester); + expect(material.color, color); }); testWidgets('Custom background color respected when presented by ScaffoldMessenger', (WidgetTester tester) async { @@ -63,7 +63,7 @@ void main() { await tester.tap(find.byKey(tapTarget)); await tester.pumpAndSettle(); - expect(_getContainerFromText(tester, contentText).color, color); + expect(_getMaterialFromText(tester, contentText).color, color); }); testWidgets('Custom content TextStyle respected', (WidgetTester tester) async { @@ -259,6 +259,97 @@ void main() { expect(contentBottomLeft.dx, lessThan(actionsTopRight.dx)); }); + group('MaterialBanner elevation', () { + Widget buildBanner(Key tapTarget, {double? elevation, double? themeElevation}) { + return MaterialApp( + theme: ThemeData(bannerTheme: MaterialBannerThemeData(elevation: themeElevation)), + home: Scaffold( + body: Builder( + builder: (BuildContext context) { + return GestureDetector( + key: tapTarget, + onTap: () { + ScaffoldMessenger.of(context).showMaterialBanner(MaterialBanner( + content: const Text('MaterialBanner'), + elevation: elevation, + actions: [ + TextButton( + child: const Text('DISMISS'), + onPressed: () => ScaffoldMessenger.of(context).hideCurrentMaterialBanner(), + ), + ], + )); + }, + behavior: HitTestBehavior.opaque, + child: const SizedBox( + height: 100.0, + width: 100.0, + ), + ); + }, + ), + ), + ); + } + + testWidgets('Elevation defaults to 0', (WidgetTester tester) async { + const Key tapTarget = Key('tap-target'); + + await tester.pumpWidget(buildBanner(tapTarget)); + await tester.tap(find.byKey(tapTarget)); + await tester.pumpAndSettle(); + expect(_getMaterialFromBanner(tester).elevation, 0.0); + await tester.tap(find.text('DISMISS')); + await tester.pumpAndSettle(); + + await tester.pumpWidget(buildBanner(tapTarget, themeElevation: 6.0)); + await tester.tap(find.byKey(tapTarget)); + await tester.pumpAndSettle(); + expect(_getMaterialFromBanner(tester).elevation, 6.0); + await tester.tap(find.text('DISMISS')); + await tester.pumpAndSettle(); + + await tester.pumpWidget(buildBanner(tapTarget, elevation: 3.0, themeElevation: 6.0)); + await tester.tap(find.byKey(tapTarget)); + await tester.pumpAndSettle(); + expect(_getMaterialFromBanner(tester).elevation, 3.0); + await tester.tap(find.text('DISMISS')); + await tester.pumpAndSettle(); + }); + + testWidgets('Uses elevation of MaterialBannerTheme by default', (WidgetTester tester) async { + const Key tapTarget = Key('tap-target'); + + await tester.pumpWidget(buildBanner(tapTarget, themeElevation: 6.0)); + await tester.tap(find.byKey(tapTarget)); + await tester.pumpAndSettle(); + expect(_getMaterialFromBanner(tester).elevation, 6.0); + await tester.tap(find.text('DISMISS')); + await tester.pumpAndSettle(); + + await tester.pumpWidget(buildBanner(tapTarget, elevation: 3.0, themeElevation: 6.0)); + await tester.tap(find.byKey(tapTarget)); + await tester.pumpAndSettle(); + expect(_getMaterialFromBanner(tester).elevation, 3.0); + await tester.tap(find.text('DISMISS')); + await tester.pumpAndSettle(); + }); + + testWidgets('Scaffold body is pushed down if elevation is 0', (WidgetTester tester) async { + const Key tapTarget = Key('tap-target'); + + await tester.pumpWidget(buildBanner(tapTarget, elevation: 0.0)); + await tester.tap(find.byKey(tapTarget)); + await tester.pumpAndSettle(); + + final Offset contentTopLeft = tester.getTopLeft(find.byKey(tapTarget)); + final Offset bannerBottomLeft = tester.getBottomLeft(find.byType(MaterialBanner)); + + expect(contentTopLeft.dx, 0.0); + expect(contentTopLeft.dy, greaterThanOrEqualTo(bannerBottomLeft.dy)); + }); + }); + testWidgets('MaterialBanner control test', (WidgetTester tester) async { const String helloMaterialBanner = 'Hello MaterialBanner'; const Key tapTarget = Key('tap-target'); @@ -984,12 +1075,12 @@ void main() { }); } -Container _getContainerFromBanner(WidgetTester tester) { - return tester.widget(find.descendant(of: find.byType(MaterialBanner), matching: find.byType(Container)).first); +Material _getMaterialFromBanner(WidgetTester tester) { + return tester.widget(find.descendant(of: find.byType(MaterialBanner), matching: find.byType(Material)).first); } -Container _getContainerFromText(WidgetTester tester, String text) { - return tester.widget(find.widgetWithText(Container, text).first); +Material _getMaterialFromText(WidgetTester tester, String text) { + return tester.widget(find.widgetWithText(Material, text).first); } RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) { diff --git a/packages/flutter/test/material/banner_theme_test.dart b/packages/flutter/test/material/banner_theme_test.dart index 62fdb9ccaa..7d4c73f97a 100644 --- a/packages/flutter/test/material/banner_theme_test.dart +++ b/packages/flutter/test/material/banner_theme_test.dart @@ -64,9 +64,9 @@ void main() { ), )); - final Container container = _getContainerFromText(tester, contentText); + final Material material = _getMaterialFromText(tester, contentText); final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); - expect(container.color, const Color(0xffffffff)); + expect(material.color, const Color(0xffffffff)); // Default value for ThemeData.typography is Typography.material2014() expect(content.text.style, Typography.material2014().englishLike.bodyText2!.merge(Typography.material2014().black.bodyText2)); }); @@ -104,9 +104,9 @@ void main() { await tester.tap(find.byKey(tapTarget)); await tester.pumpAndSettle(); - final Container container = _getContainerFromText(tester, contentText); + final Material material = _getMaterialFromText(tester, contentText); final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); - expect(container.color, const Color(0xffffffff)); + expect(material.color, const Color(0xffffffff)); // Default value for ThemeData.typography is Typography.material2014() expect(content.text.style, Typography.material2014().englishLike.bodyText2!.merge(Typography.material2014().black.bodyText2)); }); @@ -130,18 +130,18 @@ void main() { ), )); - final Container container = _getContainerFromText(tester, contentText); + final Material material = _getMaterialFromText(tester, contentText); final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); - expect(container.color, bannerTheme.backgroundColor); + expect(material.color, bannerTheme.backgroundColor); expect(content.text.style, bannerTheme.contentTextStyle); final Offset contentTopLeft = tester.getTopLeft(_textFinder(contentText)); - final Offset containerTopLeft = tester.getTopLeft(_containerFinder()); + final Offset materialTopLeft = tester.getTopLeft(_materialFinder()); final Offset leadingTopLeft = tester.getTopLeft(find.byIcon(Icons.ac_unit)); - expect(contentTopLeft.dy - containerTopLeft.dy, 24); - expect(contentTopLeft.dx - containerTopLeft.dx, 41); - expect(leadingTopLeft.dy - containerTopLeft.dy, 19); - expect(leadingTopLeft.dx - containerTopLeft.dx, 11); + expect(contentTopLeft.dy - materialTopLeft.dy, 24); + expect(contentTopLeft.dx - materialTopLeft.dx, 41); + expect(leadingTopLeft.dy - materialTopLeft.dy, 19); + expect(leadingTopLeft.dx - materialTopLeft.dx, 11); }); testWidgets('MaterialBanner uses values from MaterialBannerThemeData when presented by ScaffoldMessenger', (WidgetTester tester) async { @@ -180,18 +180,18 @@ void main() { await tester.tap(find.byKey(tapTarget)); await tester.pumpAndSettle(); - final Container container = _getContainerFromText(tester, contentText); + final Material material = _getMaterialFromText(tester, contentText); final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); - expect(container.color, bannerTheme.backgroundColor); + expect(material.color, bannerTheme.backgroundColor); expect(content.text.style, bannerTheme.contentTextStyle); final Offset contentTopLeft = tester.getTopLeft(_textFinder(contentText)); - final Offset containerTopLeft = tester.getTopLeft(_containerFinder()); + final Offset materialTopLeft = tester.getTopLeft(_materialFinder()); final Offset leadingTopLeft = tester.getTopLeft(find.byIcon(Icons.ac_unit)); - expect(contentTopLeft.dy - containerTopLeft.dy, 24); - expect(contentTopLeft.dx - containerTopLeft.dx, 41); - expect(leadingTopLeft.dy - containerTopLeft.dy, 19); - expect(leadingTopLeft.dx - containerTopLeft.dx, 11); + expect(contentTopLeft.dy - materialTopLeft.dy, 24); + expect(contentTopLeft.dx - materialTopLeft.dx, 41); + expect(leadingTopLeft.dy - materialTopLeft.dy, 19); + expect(leadingTopLeft.dx - materialTopLeft.dx, 11); }); testWidgets('MaterialBanner widget properties take priority over theme', (WidgetTester tester) async { @@ -219,18 +219,18 @@ void main() { ), )); - final Container container = _getContainerFromText(tester, contentText); + final Material material = _getMaterialFromText(tester, contentText); final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); - expect(container.color, backgroundColor); + expect(material.color, backgroundColor); expect(content.text.style, textStyle); final Offset contentTopLeft = tester.getTopLeft(_textFinder(contentText)); - final Offset containerTopLeft = tester.getTopLeft(_containerFinder()); + final Offset materialTopLeft = tester.getTopLeft(_materialFinder()); final Offset leadingTopLeft = tester.getTopLeft(find.byIcon(Icons.ac_unit)); - expect(contentTopLeft.dy - containerTopLeft.dy, 29); - expect(contentTopLeft.dx - containerTopLeft.dx, 58); - expect(leadingTopLeft.dy - containerTopLeft.dy, 24); - expect(leadingTopLeft.dx - containerTopLeft.dx, 22); + expect(contentTopLeft.dy - materialTopLeft.dy, 29); + expect(contentTopLeft.dx - materialTopLeft.dx, 58); + expect(leadingTopLeft.dy - materialTopLeft.dy, 24); + expect(leadingTopLeft.dx - materialTopLeft.dx, 22); }); testWidgets('MaterialBanner widget properties take priority over theme when presented by ScaffoldMessenger', (WidgetTester tester) async { @@ -275,18 +275,18 @@ void main() { await tester.tap(find.byKey(tapTarget)); await tester.pumpAndSettle(); - final Container container = _getContainerFromText(tester, contentText); + final Material material = _getMaterialFromText(tester, contentText); final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); - expect(container.color, backgroundColor); + expect(material.color, backgroundColor); expect(content.text.style, textStyle); final Offset contentTopLeft = tester.getTopLeft(_textFinder(contentText)); - final Offset containerTopLeft = tester.getTopLeft(_containerFinder()); + final Offset materialTopLeft = tester.getTopLeft(_materialFinder()); final Offset leadingTopLeft = tester.getTopLeft(find.byIcon(Icons.ac_unit)); - expect(contentTopLeft.dy - containerTopLeft.dy, 29); - expect(contentTopLeft.dx - containerTopLeft.dx, 58); - expect(leadingTopLeft.dy - containerTopLeft.dy, 24); - expect(leadingTopLeft.dx - containerTopLeft.dx, 22); + expect(contentTopLeft.dy - materialTopLeft.dy, 29); + expect(contentTopLeft.dx - materialTopLeft.dx, 58); + expect(leadingTopLeft.dy - materialTopLeft.dy, 24); + expect(leadingTopLeft.dx - materialTopLeft.dx, 22); }); testWidgets('MaterialBanner uses color scheme when necessary', (WidgetTester tester) async { @@ -307,8 +307,8 @@ void main() { ), )); - final Container container = _getContainerFromText(tester, contentText); - expect(container.color, colorScheme.surface); + final Material material = _getMaterialFromText(tester, contentText); + expect(material.color, colorScheme.surface); }); testWidgets('MaterialBanner uses color scheme when necessary when presented by ScaffoldMessenger', (WidgetTester tester) async { @@ -346,8 +346,8 @@ void main() { await tester.tap(find.byKey(tapTarget)); await tester.pumpAndSettle(); - final Container container = _getContainerFromText(tester, contentText); - expect(container.color, colorScheme.surface); + final Material material = _getMaterialFromText(tester, contentText); + expect(material.color, colorScheme.surface); }); } @@ -360,12 +360,12 @@ MaterialBannerThemeData _bannerTheme() { ); } -Container _getContainerFromText(WidgetTester tester, String text) { - return tester.widget(find.widgetWithText(Container, text).first); +Material _getMaterialFromText(WidgetTester tester, String text) { + return tester.widget(find.widgetWithText(Material, text).first); } -Finder _containerFinder() { - return find.descendant(of: find.byType(MaterialBanner), matching: find.byType(Container)).first; +Finder _materialFinder() { + return find.descendant(of: find.byType(MaterialBanner), matching: find.byType(Material)).first; } RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) { diff --git a/packages/flutter/test/material/inherited_theme_test.dart b/packages/flutter/test/material/inherited_theme_test.dart index 9c05d62a69..5b78b6c1a7 100644 --- a/packages/flutter/test/material/inherited_theme_test.dart +++ b/packages/flutter/test/material/inherited_theme_test.dart @@ -211,8 +211,8 @@ void main() { } Color bannerColor() { - return tester.widget( - find.descendant(of: find.byType(MaterialBanner), matching: find.byType(Container)).first, + return tester.widget( + find.descendant(of: find.byType(MaterialBanner), matching: find.byType(Material)).first, ).color!; }