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
be0c3709
Unverified
Commit
be0c3709
authored
Jul 19, 2022
by
Romain Rastel
Committed by
GitHub
Jul 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add transitionOnUserGestures to true on SnackBar for back swipe (#106638)
parent
dbe38eec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
snack_bar.dart
packages/flutter/lib/src/material/snack_bar.dart
+8
-0
snack_bar_test.dart
packages/flutter/test/material/snack_bar_test.dart
+76
-0
No files found.
packages/flutter/lib/src/material/snack_bar.dart
View file @
be0c3709
...
...
@@ -158,6 +158,13 @@ class _SnackBarActionState extends State<SnackBarAction> {
/// A SnackBar with an action will not time out when TalkBack or VoiceOver are
/// enabled. This is controlled by [AccessibilityFeatures.accessibleNavigation].
///
/// During page transitions, the [SnackBar] will smoothly animate to its
/// location on the other page. For example if the [SnackBar.behavior] is set to
/// [SnackBarBehavior.floating] and the next page has a floating action button,
/// while the current one does not, the [SnackBar] will smoothly animate above
/// the floating action button. It also works in the case of a back gesture
/// transition.
///
/// {@tool dartpad}
/// Here is an example of a [SnackBar] with an [action] button implemented using
/// [SnackBarAction].
...
...
@@ -620,6 +627,7 @@ class _SnackBarState extends State<SnackBar> {
return
Hero
(
tag:
'<SnackBar Hero tag -
${widget.content}
>'
,
transitionOnUserGestures:
true
,
child:
ClipRect
(
clipBehavior:
widget
.
clipBehavior
,
child:
snackBarTransition
,
...
...
packages/flutter/test/material/snack_bar_test.dart
View file @
be0c3709
...
...
@@ -1795,6 +1795,82 @@ void main() {
expect
(
find
.
text
(
secondHeader
),
findsOneWidget
);
});
testWidgets
(
'Should have only one SnackBar during back swipe navigation'
,
(
WidgetTester
tester
)
async
{
const
String
snackBarText
=
'hello snackbar'
;
const
Key
snackTarget
=
Key
(
'snack-target'
);
const
Key
transitionTarget
=
Key
(
'transition-target'
);
Widget
buildApp
()
{
final
PageTransitionsTheme
pageTransitionTheme
=
PageTransitionsTheme
(
builders:
<
TargetPlatform
,
PageTransitionsBuilder
>{
for
(
final
TargetPlatform
platform
in
TargetPlatform
.
values
)
platform:
const
CupertinoPageTransitionsBuilder
(),
},
);
return
MaterialApp
(
theme:
ThemeData
(
pageTransitionsTheme:
pageTransitionTheme
),
initialRoute:
'/'
,
routes:
<
String
,
WidgetBuilder
>
{
'/'
:
(
BuildContext
context
)
{
return
Scaffold
(
body:
Center
(
child:
ElevatedButton
(
key:
transitionTarget
,
child:
const
Text
(
'PUSH'
),
onPressed:
()
{
Navigator
.
of
(
context
).
pushNamed
(
'/second'
);
},
),
),
);
},
'/second'
:
(
BuildContext
context
)
{
return
Scaffold
(
floatingActionButton:
FloatingActionButton
(
key:
snackTarget
,
onPressed:
()
async
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
const
SnackBar
(
content:
Text
(
snackBarText
),
),
);
},
child:
const
Text
(
'X'
),
),
);
},
},
);
}
await
tester
.
pumpWidget
(
buildApp
());
// Transition to second page.
await
tester
.
tap
(
find
.
byKey
(
transitionTarget
));
await
tester
.
pumpAndSettle
();
// Present SnackBar
await
tester
.
tap
(
find
.
byKey
(
snackTarget
));
await
tester
.
pump
();
// schedule animation
expect
(
find
.
text
(
snackBarText
),
findsOneWidget
);
await
tester
.
pump
();
// begin animation
expect
(
find
.
text
(
snackBarText
),
findsOneWidget
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
750
));
expect
(
find
.
text
(
snackBarText
),
findsOneWidget
);
// Start the gesture at the edge of the screen.
final
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
5.0
,
200.0
));
// Trigger the swipe.
await
gesture
.
moveBy
(
const
Offset
(
100.0
,
0.0
));
// Back gestures should trigger and draw the hero transition in the very same
// frame (since the "from" route has already moved to reveal the "to" route).
await
tester
.
pump
();
// We should have only one SnackBar displayed on the screen.
expect
(
find
.
text
(
snackBarText
),
findsOneWidget
);
});
testWidgets
(
'SnackBars should be shown above the bottomSheet'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
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