Unverified Commit 4d501ab0 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix some `MaterialBanner` properties aren't respected when presented by...

Fix some `MaterialBanner` properties aren't respected when presented by `ScaffoldMessenger` (#124024)

Fix some `MaterialBanner` properties aren't respected when presented by `ScaffoldMessenger`
parent 193455b1
...@@ -245,6 +245,9 @@ class MaterialBanner extends StatefulWidget { ...@@ -245,6 +245,9 @@ class MaterialBanner extends StatefulWidget {
elevation: elevation, elevation: elevation,
leading: leading, leading: leading,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
surfaceTintColor: surfaceTintColor,
shadowColor: shadowColor,
dividerColor: dividerColor,
padding: padding, padding: padding,
margin: margin, margin: margin,
leadingPadding: leadingPadding, leadingPadding: leadingPadding,
......
...@@ -7,71 +7,21 @@ import 'package:flutter/rendering.dart'; ...@@ -7,71 +7,21 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Custom background color respected', (WidgetTester tester) async { testWidgets('MaterialBanner properties are respected', (WidgetTester tester) async {
const Color color = Colors.pink;
await tester.pumpWidget(
MaterialApp(
home: MaterialBanner(
backgroundColor: color,
content: const Text('I am a banner'),
actions: <Widget>[
TextButton(
child: const Text('Action'),
onPressed: () { },
),
],
),
),
);
final Material material = _getMaterialFromBanner(tester);
expect(material.color, color);
});
testWidgets('Custom background color respected when presented by ScaffoldMessenger', (WidgetTester tester) async {
const Color color = Colors.pink;
const String contentText = 'Content';
const Key tapTarget = Key('tap-target');
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: Builder(
builder: (BuildContext context) {
return GestureDetector(
key: tapTarget,
onTap: () {
ScaffoldMessenger.of(context).showMaterialBanner(MaterialBanner(
content: const Text(contentText),
backgroundColor: color,
actions: <Widget>[
TextButton(
child: const Text('DISMISS'),
onPressed: () => ScaffoldMessenger.of(context).hideCurrentMaterialBanner(),
),
],
));
},
behavior: HitTestBehavior.opaque,
child: const SizedBox(
height: 100.0,
width: 100.0,
),
);
},
),
),
));
await tester.tap(find.byKey(tapTarget));
await tester.pumpAndSettle();
expect(_getMaterialFromText(tester, contentText).color, color);
});
testWidgets('Custom content TextStyle respected', (WidgetTester tester) async {
const String contentText = 'Content'; const String contentText = 'Content';
const Color backgroundColor = Colors.pink;
const Color surfaceTintColor = Colors.green;
const Color shadowColor = Colors.blue;
const Color dividerColor = Colors.yellow;
const TextStyle contentTextStyle = TextStyle(color: Colors.pink); const TextStyle contentTextStyle = TextStyle(color: Colors.pink);
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: MaterialBanner( home: MaterialBanner(
backgroundColor: backgroundColor,
surfaceTintColor: surfaceTintColor,
shadowColor: shadowColor,
dividerColor: dividerColor,
contentTextStyle: contentTextStyle, contentTextStyle: contentTextStyle,
content: const Text(contentText), content: const Text(contentText),
actions: <Widget>[ actions: <Widget>[
...@@ -84,14 +34,28 @@ void main() { ...@@ -84,14 +34,28 @@ void main() {
), ),
); );
final Material material = _getMaterialFromBanner(tester);
expect(material.elevation, 0.0);
expect(material.color, backgroundColor);
expect(material.surfaceTintColor, surfaceTintColor);
expect(material.shadowColor, shadowColor);
final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText);
expect(content.text.style, contentTextStyle); expect(content.text.style, contentTextStyle);
final Divider divider = tester.widget<Divider>(find.byType(Divider));
expect(divider.color, dividerColor);
}); });
testWidgets('Custom content TextStyle respected when presented by ScaffoldMessenger', (WidgetTester tester) async { testWidgets('MaterialBanner properties are respected when presented by ScaffoldMessenger', (WidgetTester tester) async {
const TextStyle contentTextStyle = TextStyle(color: Colors.pink);
const String contentText = 'Content'; const String contentText = 'Content';
const Key tapTarget = Key('tap-target'); const Key tapTarget = Key('tap-target');
const Color backgroundColor = Colors.pink;
const Color surfaceTintColor = Colors.green;
const Color shadowColor = Colors.blue;
const Color dividerColor = Colors.yellow;
const TextStyle contentTextStyle = TextStyle(color: Colors.pink);
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
home: Scaffold( home: Scaffold(
body: Builder( body: Builder(
...@@ -101,6 +65,10 @@ void main() { ...@@ -101,6 +65,10 @@ void main() {
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showMaterialBanner(MaterialBanner( ScaffoldMessenger.of(context).showMaterialBanner(MaterialBanner(
content: const Text(contentText), content: const Text(contentText),
backgroundColor: backgroundColor,
surfaceTintColor: surfaceTintColor,
shadowColor: shadowColor,
dividerColor: dividerColor,
contentTextStyle: contentTextStyle, contentTextStyle: contentTextStyle,
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
...@@ -123,8 +91,17 @@ void main() { ...@@ -123,8 +91,17 @@ void main() {
await tester.tap(find.byKey(tapTarget)); await tester.tap(find.byKey(tapTarget));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final Material material = _getMaterialFromText(tester, contentText);
expect(material.elevation, 0.0);
expect(material.color, backgroundColor);
expect(material.surfaceTintColor, surfaceTintColor);
expect(material.shadowColor, shadowColor);
final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText); final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText);
expect(content.text.style, contentTextStyle); expect(content.text.style, contentTextStyle);
final Divider divider = tester.widget<Divider>(find.byType(Divider));
expect(divider.color, dividerColor);
}); });
testWidgets('Actions laid out below content if more than one action', (WidgetTester tester) async { testWidgets('Actions laid out below content if more than one action', (WidgetTester tester) async {
......
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