Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
efe0c5eb
Unverified
Commit
efe0c5eb
authored
Jun 10, 2021
by
Aayan
Committed by
GitHub
Jun 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate MaterialBanner with the ScaffoldMessenger API (#81706)
parent
734df6f5
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1413 additions
and
49 deletions
+1413
-49
banner.dart
packages/flutter/lib/src/material/banner.dart
+220
-13
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+242
-26
banner_test.dart
packages/flutter/test/material/banner_test.dart
+701
-3
banner_theme_test.dart
packages/flutter/test/material/banner_theme_test.dart
+193
-7
snack_bar_test.dart
packages/flutter/test/material/snack_bar_test.dart
+57
-0
No files found.
packages/flutter/lib/src/material/banner.dart
View file @
efe0c5eb
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/material/scaffold.dart
View file @
efe0c5eb
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/banner_test.dart
View file @
efe0c5eb
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/banner_theme_test.dart
View file @
efe0c5eb
...
...
@@ -64,7 +64,47 @@ void main() {
),
));
final
Container
container
=
_getContainerFromBanner
(
tester
);
final
Container
container
=
_getContainerFromText
(
tester
,
contentText
);
final
RenderParagraph
content
=
_getTextRenderObjectFromDialog
(
tester
,
contentText
);
expect
(
container
.
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
));
});
testWidgets
(
'Passing no MaterialBannerThemeData returns defaults when presented by ScaffoldMessenger'
,
(
WidgetTester
tester
)
async
{
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
),
actions:
<
Widget
>[
TextButton
(
child:
const
Text
(
'Action'
),
onPressed:
()
{
},
),
],
));
},
behavior:
HitTestBehavior
.
opaque
,
child:
const
SizedBox
(
height:
100.0
,
width:
100.0
,
),
);
},
),
),
));
await
tester
.
tap
(
find
.
byKey
(
tapTarget
));
await
tester
.
pumpAndSettle
();
final
Container
container
=
_getContainerFromText
(
tester
,
contentText
);
final
RenderParagraph
content
=
_getTextRenderObjectFromDialog
(
tester
,
contentText
);
expect
(
container
.
color
,
const
Color
(
0xffffffff
));
// Default value for ThemeData.typography is Typography.material2014()
...
...
@@ -90,7 +130,57 @@ void main() {
),
));
final
Container
container
=
_getContainerFromBanner
(
tester
);
final
Container
container
=
_getContainerFromText
(
tester
,
contentText
);
final
RenderParagraph
content
=
_getTextRenderObjectFromDialog
(
tester
,
contentText
);
expect
(
container
.
color
,
bannerTheme
.
backgroundColor
);
expect
(
content
.
text
.
style
,
bannerTheme
.
contentTextStyle
);
final
Offset
contentTopLeft
=
tester
.
getTopLeft
(
_textFinder
(
contentText
));
final
Offset
containerTopLeft
=
tester
.
getTopLeft
(
_containerFinder
());
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
);
});
testWidgets
(
'MaterialBanner uses values from MaterialBannerThemeData when presented by ScaffoldMessenger'
,
(
WidgetTester
tester
)
async
{
final
MaterialBannerThemeData
bannerTheme
=
_bannerTheme
();
const
String
contentText
=
'Content'
;
const
Key
tapTarget
=
Key
(
'tap-target'
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
bannerTheme:
bannerTheme
),
home:
Scaffold
(
body:
Builder
(
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
key:
tapTarget
,
onTap:
()
{
ScaffoldMessenger
.
of
(
context
).
showMaterialBanner
(
MaterialBanner
(
leading:
const
Icon
(
Icons
.
ac_unit
),
content:
const
Text
(
contentText
),
actions:
<
Widget
>[
TextButton
(
child:
const
Text
(
'Action'
),
onPressed:
()
{
},
),
],
));
},
behavior:
HitTestBehavior
.
opaque
,
child:
const
SizedBox
(
height:
100.0
,
width:
100.0
,
),
);
},
),
),
));
await
tester
.
tap
(
find
.
byKey
(
tapTarget
));
await
tester
.
pumpAndSettle
();
final
Container
container
=
_getContainerFromText
(
tester
,
contentText
);
final
RenderParagraph
content
=
_getTextRenderObjectFromDialog
(
tester
,
contentText
);
expect
(
container
.
color
,
bannerTheme
.
backgroundColor
);
expect
(
content
.
text
.
style
,
bannerTheme
.
contentTextStyle
);
...
...
@@ -129,7 +219,63 @@ void main() {
),
));
final
Container
container
=
_getContainerFromBanner
(
tester
);
final
Container
container
=
_getContainerFromText
(
tester
,
contentText
);
final
RenderParagraph
content
=
_getTextRenderObjectFromDialog
(
tester
,
contentText
);
expect
(
container
.
color
,
backgroundColor
);
expect
(
content
.
text
.
style
,
textStyle
);
final
Offset
contentTopLeft
=
tester
.
getTopLeft
(
_textFinder
(
contentText
));
final
Offset
containerTopLeft
=
tester
.
getTopLeft
(
_containerFinder
());
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
);
});
testWidgets
(
'MaterialBanner widget properties take priority over theme when presented by ScaffoldMessenger'
,
(
WidgetTester
tester
)
async
{
const
Color
backgroundColor
=
Colors
.
purple
;
const
TextStyle
textStyle
=
TextStyle
(
color:
Colors
.
green
);
final
MaterialBannerThemeData
bannerTheme
=
_bannerTheme
();
const
String
contentText
=
'Content'
;
const
Key
tapTarget
=
Key
(
'tap-target'
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
bannerTheme:
bannerTheme
),
home:
Scaffold
(
body:
Builder
(
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
key:
tapTarget
,
onTap:
()
{
ScaffoldMessenger
.
of
(
context
).
showMaterialBanner
(
MaterialBanner
(
backgroundColor:
backgroundColor
,
leading:
const
Icon
(
Icons
.
ac_unit
),
contentTextStyle:
textStyle
,
content:
const
Text
(
contentText
),
padding:
const
EdgeInsets
.
all
(
10
),
leadingPadding:
const
EdgeInsets
.
all
(
12
),
actions:
<
Widget
>[
TextButton
(
child:
const
Text
(
'Action'
),
onPressed:
()
{
},
),
],
));
},
behavior:
HitTestBehavior
.
opaque
,
child:
const
SizedBox
(
height:
100.0
,
width:
100.0
,
),
);
},
),
),
));
await
tester
.
tap
(
find
.
byKey
(
tapTarget
));
await
tester
.
pumpAndSettle
();
final
Container
container
=
_getContainerFromText
(
tester
,
contentText
);
final
RenderParagraph
content
=
_getTextRenderObjectFromDialog
(
tester
,
contentText
);
expect
(
container
.
color
,
backgroundColor
);
expect
(
content
.
text
.
style
,
textStyle
);
...
...
@@ -145,11 +291,12 @@ void main() {
testWidgets
(
'MaterialBanner uses color scheme when necessary'
,
(
WidgetTester
tester
)
async
{
final
ColorScheme
colorScheme
=
const
ColorScheme
.
light
().
copyWith
(
surface:
Colors
.
purple
);
const
String
contentText
=
'Content'
;
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
colorScheme:
colorScheme
),
home:
Scaffold
(
body:
MaterialBanner
(
content:
const
Text
(
'Content'
),
content:
const
Text
(
contentText
),
actions:
<
Widget
>[
TextButton
(
child:
const
Text
(
'Action'
),
...
...
@@ -160,7 +307,46 @@ void main() {
),
));
final
Container
container
=
_getContainerFromBanner
(
tester
);
final
Container
container
=
_getContainerFromText
(
tester
,
contentText
);
expect
(
container
.
color
,
colorScheme
.
surface
);
});
testWidgets
(
'MaterialBanner uses color scheme when necessary when presented by ScaffoldMessenger'
,
(
WidgetTester
tester
)
async
{
final
ColorScheme
colorScheme
=
const
ColorScheme
.
light
().
copyWith
(
surface:
Colors
.
purple
);
const
String
contentText
=
'Content'
;
const
Key
tapTarget
=
Key
(
'tap-target'
);
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
colorScheme:
colorScheme
),
home:
Scaffold
(
body:
Builder
(
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
key:
tapTarget
,
onTap:
()
{
ScaffoldMessenger
.
of
(
context
).
showMaterialBanner
(
MaterialBanner
(
content:
const
Text
(
contentText
),
actions:
<
Widget
>[
TextButton
(
child:
const
Text
(
'Action'
),
onPressed:
()
{
},
),
],
));
},
behavior:
HitTestBehavior
.
opaque
,
child:
const
SizedBox
(
height:
100.0
,
width:
100.0
,
),
);
},
),
),
));
await
tester
.
tap
(
find
.
byKey
(
tapTarget
));
await
tester
.
pumpAndSettle
();
final
Container
container
=
_getContainerFromText
(
tester
,
contentText
);
expect
(
container
.
color
,
colorScheme
.
surface
);
});
}
...
...
@@ -174,8 +360,8 @@ MaterialBannerThemeData _bannerTheme() {
);
}
Container
_getContainerFrom
Banner
(
WidgetTester
tester
)
{
return
tester
.
widget
<
Container
>(
_containerFinder
()
);
Container
_getContainerFrom
Text
(
WidgetTester
tester
,
String
text
)
{
return
tester
.
widget
<
Container
>(
find
.
widgetWithText
(
Container
,
text
).
first
);
}
Finder
_containerFinder
(
)
{
...
...
packages/flutter/test/material/snack_bar_test.dart
View file @
efe0c5eb
...
...
@@ -2282,6 +2282,63 @@ void main() {
await
expectLater
(
find
.
byType
(
MaterialApp
),
matchesGoldenFile
(
'snack_bar.goldenTest.workWithBottomSheet.png'
));
});
testWidgets
(
'ScaffoldMessenger does not duplicate a SnackBar when presenting a MaterialBanner.'
,
(
WidgetTester
tester
)
async
{
const
Key
materialBannerTapTarget
=
Key
(
'materialbanner-tap-target'
);
const
Key
snackBarTapTarget
=
Key
(
'snackbar-tap-target'
);
const
String
snackBarText
=
'SnackBar'
;
const
String
materialBannerText
=
'MaterialBanner'
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Builder
(
builder:
(
BuildContext
context
)
{
return
Column
(
children:
<
Widget
>[
GestureDetector
(
key:
snackBarTapTarget
,
onTap:
()
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
const
SnackBar
(
content:
Text
(
snackBarText
),
));
},
behavior:
HitTestBehavior
.
opaque
,
child:
const
SizedBox
(
height:
100.0
,
width:
100.0
,
),
),
GestureDetector
(
key:
materialBannerTapTarget
,
onTap:
()
{
ScaffoldMessenger
.
of
(
context
).
showMaterialBanner
(
MaterialBanner
(
content:
const
Text
(
materialBannerText
),
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
(
snackBarTapTarget
));
await
tester
.
tap
(
find
.
byKey
(
materialBannerTapTarget
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
snackBarText
),
findsOneWidget
);
expect
(
find
.
text
(
materialBannerText
),
findsOneWidget
);
});
testWidgets
(
'ScaffoldMessenger presents SnackBars to only the root Scaffold when Scaffolds are nested.'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment