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 {
elevation: elevation,
leading: leading,
backgroundColor: backgroundColor,
surfaceTintColor: surfaceTintColor,
shadowColor: shadowColor,
dividerColor: dividerColor,
padding: padding,
margin: margin,
leadingPadding: leadingPadding,
......
......@@ -7,71 +7,21 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Custom background color 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 {
testWidgets('MaterialBanner properties are respected', (WidgetTester tester) async {
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);
await tester.pumpWidget(
MaterialApp(
home: MaterialBanner(
backgroundColor: backgroundColor,
surfaceTintColor: surfaceTintColor,
shadowColor: shadowColor,
dividerColor: dividerColor,
contentTextStyle: contentTextStyle,
content: const Text(contentText),
actions: <Widget>[
......@@ -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);
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 {
const TextStyle contentTextStyle = TextStyle(color: Colors.pink);
testWidgets('MaterialBanner properties are respected when presented by ScaffoldMessenger', (WidgetTester tester) async {
const String contentText = 'Content';
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(
home: Scaffold(
body: Builder(
......@@ -101,6 +65,10 @@ void main() {
onTap: () {
ScaffoldMessenger.of(context).showMaterialBanner(MaterialBanner(
content: const Text(contentText),
backgroundColor: backgroundColor,
surfaceTintColor: surfaceTintColor,
shadowColor: shadowColor,
dividerColor: dividerColor,
contentTextStyle: contentTextStyle,
actions: <Widget>[
TextButton(
......@@ -123,8 +91,17 @@ void main() {
await tester.tap(find.byKey(tapTarget));
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);
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 {
......
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