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
aa16a8ca
Unverified
Commit
aa16a8ca
authored
Mar 02, 2021
by
Chinmoy
Committed by
GitHub
Mar 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added clearSnackBars method to ScaffoldMessengerState (#76146)
parent
3594d1aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+11
-0
snack_bar_test.dart
packages/flutter/test/material/snack_bar_test.dart
+50
-0
No files found.
packages/flutter/lib/src/material/scaffold.dart
View file @
aa16a8ca
...
...
@@ -432,6 +432,17 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide
_snackBarTimer
=
null
;
}
/// Removes all the snackBars currently in queue by clearing the queue
/// and running normal exit animation on the current snackBar.
void
clearSnackBars
()
{
if
(
_snackBars
.
isEmpty
||
_snackBarController
!.
status
==
AnimationStatus
.
dismissed
)
return
;
final
ScaffoldFeatureController
<
SnackBar
,
SnackBarClosedReason
>
currentSnackbar
=
_snackBars
.
first
;
_snackBars
.
clear
();
_snackBars
.
add
(
currentSnackbar
);
hideCurrentSnackBar
();
}
@override
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMediaQuery
(
context
));
...
...
packages/flutter/test/material/snack_bar_test.dart
View file @
aa16a8ca
...
...
@@ -2323,4 +2323,54 @@ void main() {
final
Offset
snackBarTopRight
=
tester
.
getTopRight
(
find
.
byType
(
SnackBar
));
expect
(
snackBarTopRight
.
dy
,
465.0
);
});
testWidgets
(
'ScaffoldMessengerState clearSnackBars works as expected'
,
(
WidgetTester
tester
)
async
{
final
List
<
String
>
snackBars
=
<
String
>[
'Hello Snackbar'
,
'Hi Snackbar'
,
'Bye Snackbar'
];
int
snackBarCounter
=
0
;
const
Key
tapTarget
=
Key
(
'tap-target'
);
final
GlobalKey
<
ScaffoldMessengerState
>
scaffoldMessengerKey
=
GlobalKey
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
ScaffoldMessenger
(
key:
scaffoldMessengerKey
,
child:
Scaffold
(
body:
Builder
(
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
key:
tapTarget
,
onTap:
()
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
Text
(
snackBars
[
snackBarCounter
++]),
duration:
const
Duration
(
seconds:
2
),
));
},
behavior:
HitTestBehavior
.
opaque
,
child:
Container
(
height:
100.0
,
width:
100.0
,
),
);
}
),
),
),
));
expect
(
find
.
text
(
snackBars
[
0
]),
findsNothing
);
expect
(
find
.
text
(
snackBars
[
1
]),
findsNothing
);
expect
(
find
.
text
(
snackBars
[
2
]),
findsNothing
);
await
tester
.
tap
(
find
.
byKey
(
tapTarget
));
await
tester
.
tap
(
find
.
byKey
(
tapTarget
));
await
tester
.
tap
(
find
.
byKey
(
tapTarget
));
expect
(
find
.
text
(
snackBars
[
0
]),
findsNothing
);
expect
(
find
.
text
(
snackBars
[
1
]),
findsNothing
);
expect
(
find
.
text
(
snackBars
[
2
]),
findsNothing
);
await
tester
.
pump
();
// schedule animation
expect
(
find
.
text
(
snackBars
[
0
]),
findsOneWidget
);
scaffoldMessengerKey
.
currentState
!.
clearSnackBars
();
expect
(
find
.
text
(
snackBars
[
0
]),
findsOneWidget
);
await
tester
.
pump
(
const
Duration
(
seconds:
2
));
expect
(
find
.
text
(
snackBars
[
0
]),
findsNothing
);
expect
(
find
.
text
(
snackBars
[
1
]),
findsNothing
);
expect
(
find
.
text
(
snackBars
[
2
]),
findsNothing
);
});
}
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