diff --git a/packages/flutter/lib/src/cupertino/route.dart b/packages/flutter/lib/src/cupertino/route.dart index 5eccb7ba6f..2f2e28640f 100644 --- a/packages/flutter/lib/src/cupertino/route.dart +++ b/packages/flutter/lib/src/cupertino/route.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:async'; +import 'dart:math'; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; @@ -518,13 +519,19 @@ class _CupertinoBackGestureDetectorState extends State<_CupertinoBackGestureD @override Widget build(BuildContext context) { assert(debugCheckHasDirectionality(context)); + // For devices with notches, the drag area needs to be larger on the side + // that has the notch. + double dragAreaWidth = Directionality.of(context) == TextDirection.ltr ? + MediaQuery.of(context).padding.left : + MediaQuery.of(context).padding.right; + dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth); return Stack( fit: StackFit.passthrough, children: [ widget.child, PositionedDirectional( start: 0.0, - width: _kBackGestureWidth, + width: dragAreaWidth, top: 0.0, bottom: 0.0, child: Listener( diff --git a/packages/flutter/test/cupertino/page_test.dart b/packages/flutter/test/cupertino/page_test.dart index a6de3b22fc..b9970392ba 100644 --- a/packages/flutter/test/cupertino/page_test.dart +++ b/packages/flutter/test/cupertino/page_test.dart @@ -265,6 +265,98 @@ void main() { expect(find.text('Page 2'), isOnstage); }); + testWidgets('test edge swipes work with media query padding (LTR)', (WidgetTester tester) async { + await tester.pumpWidget( + CupertinoApp( + builder: (BuildContext context, Widget navigator) { + return MediaQuery( + data: const MediaQueryData(padding: EdgeInsets.only(left: 40)), + child: navigator, + ); + }, + home: const Placeholder(), + ), + ); + + tester.state(find.byType(Navigator)).push( + CupertinoPageRoute( + builder: (BuildContext context) => const Center(child: Text('Page 1')), + ), + ); + + await tester.pump(); + await tester.pump(const Duration(milliseconds: 400)); + + tester.state(find.byType(Navigator)).push( + CupertinoPageRoute( + builder: (BuildContext context) => const Center(child: Text('Page 2')), + ), + ); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 400)); + + expect(find.text('Page 1'), findsNothing); + expect(find.text('Page 2'), isOnstage); + + // Now drag from the left edge. + final TestGesture gesture = await tester.startGesture(const Offset(35.0, 200.0)); + await gesture.moveBy(const Offset(300.0, 0.0)); + await tester.pump(); + await tester.pumpAndSettle(); + + // Page 1 is now visible. + expect(find.text('Page 1'), isOnstage); + expect(find.text('Page 2'), isOnstage); + }); + + testWidgets('test edge swipes work with media query padding (RLT)', (WidgetTester tester) async { + await tester.pumpWidget( + CupertinoApp( + builder: (BuildContext context, Widget navigator) { + return Directionality( + textDirection: TextDirection.rtl, + child: MediaQuery( + data: const MediaQueryData(padding: EdgeInsets.only(right: 40)), + child: navigator, + ), + ); + }, + home: const Placeholder(), + ), + ); + + tester.state(find.byType(Navigator)).push( + CupertinoPageRoute( + builder: (BuildContext context) => const Center(child: Text('Page 1')), + ), + ); + + await tester.pump(); + await tester.pump(const Duration(milliseconds: 400)); + + tester.state(find.byType(Navigator)).push( + CupertinoPageRoute( + builder: (BuildContext context) => const Center(child: Text('Page 2')), + ), + ); + + await tester.pump(); + await tester.pump(const Duration(milliseconds: 400)); + + expect(find.text('Page 1'), findsNothing); + expect(find.text('Page 2'), isOnstage); + + // Now drag from the left edge. + final TestGesture gesture = await tester.startGesture(const Offset(765.0, 200.0)); + await gesture.moveBy(const Offset(-300.0, 0.0)); + await tester.pump(); + await tester.pumpAndSettle(); + + // Page 1 is now visible. + expect(find.text('Page 1'), isOnstage); + expect(find.text('Page 2'), isOnstage); + }); + testWidgets('test only edge swipes work (RTL)', (WidgetTester tester) async { await tester.pumpWidget( CupertinoApp(