Add transitionOnUserGestures to true on SnackBar for back swipe (#106638)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user