Skip to content

Commit 4fc3e81

Browse files
authored
[cupertino_ui] Fix covered sheet revealing root route through top gap (flutter#12530)
Ports flutter#187058 to `cupertino_ui` following flutter#188444. Fixes flutter#187057. When multiple `CupertinoSheetRoute`s are stacked, the covered sheet's top gap can reveal the root route because the top-gap padding sits outside the secondary route transition. This change applies the covered sheet's secondary transition outside the top-gap padding, so the sheet and its gap move together. It also adds a coordinate-based regression test that verifies the root route remains fully covered. ## Tests - `flutter test test/sheet_test.dart --no-pub` - `dart run script/tool/bin/flutter_plugin_tools.dart analyze --packages cupertino_ui` - `dart run script/tool/bin/flutter_plugin_tools.dart validate --packages cupertino_ui --base-sha=252bb33ad3666c7d28621c87edccafff86e210fd --check-for-missing-changes` - `dart run script/tool/bin/flutter_plugin_tools.dart publish-check --packages cupertino_ui` ## Pre-Review Checklist
1 parent 4bc6e39 commit 4fc3e81

3 files changed

Lines changed: 89 additions & 7 deletions

File tree

‎packages/cupertino_ui/lib/src/sheet.dart‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,13 @@ class _CupertinoSheetTransitionState extends State<CupertinoSheetTransition>
552552
child: AnimatedBuilder(
553553
animation: _stretchDragAnimation,
554554
builder: (BuildContext context, Widget? child) {
555-
return Padding(
556-
padding: EdgeInsets.only(
557-
top: MediaQuery.heightOf(context) * _stretchDragAnimation.value,
558-
),
559-
child: _coverSheetSecondaryTransition(
560-
widget.secondaryRouteAnimation,
561-
_coverSheetPrimaryTransition(
555+
return _coverSheetSecondaryTransition(
556+
widget.secondaryRouteAnimation,
557+
Padding(
558+
padding: EdgeInsets.only(
559+
top: MediaQuery.heightOf(context) * _stretchDragAnimation.value,
560+
),
561+
child: _coverSheetPrimaryTransition(
562562
context,
563563
widget.primaryRouteAnimation,
564564
widget.linearTransition,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Fixes lower routes being revealed through the top gap when multiple `CupertinoSheetRoute`s are stacked.
3+
version: patch

‎packages/cupertino_ui/test/sheet_test.dart‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,85 @@ void main() {
317317
);
318318
});
319319

320+
testWidgets('covered sheet does not reveal the root route through its top gap', (
321+
WidgetTester tester,
322+
) async {
323+
final GlobalKey scaffoldKey = GlobalKey();
324+
325+
await tester.pumpWidget(
326+
CupertinoApp(
327+
home: CupertinoPageScaffold(
328+
key: scaffoldKey,
329+
child: Column(
330+
children: <Widget>[
331+
const Text('Page 1'),
332+
CupertinoButton(
333+
onPressed: () {
334+
Navigator.push<void>(
335+
scaffoldKey.currentContext!,
336+
CupertinoSheetRoute<void>(
337+
builder: (BuildContext context) {
338+
return CupertinoPageScaffold(
339+
child: Column(
340+
children: <Widget>[
341+
const Text('Page 2'),
342+
CupertinoButton(
343+
onPressed: () {
344+
Navigator.push<void>(
345+
context,
346+
CupertinoSheetRoute<void>(
347+
builder: (BuildContext context) {
348+
return const CupertinoPageScaffold(child: Text('Page 3'));
349+
},
350+
),
351+
);
352+
},
353+
child: const Text('Push Page 3'),
354+
),
355+
],
356+
),
357+
);
358+
},
359+
),
360+
);
361+
},
362+
child: const Text('Push Page 2'),
363+
),
364+
],
365+
),
366+
),
367+
),
368+
);
369+
370+
await tester.tap(find.text('Push Page 2'));
371+
await tester.pumpAndSettle();
372+
373+
await tester.tap(find.text('Push Page 3'));
374+
await tester.pumpAndSettle();
375+
376+
final double page1Top = tester
377+
.getTopLeft(
378+
find.ancestor(of: find.text('Page 1'), matching: find.byType(CupertinoPageScaffold)),
379+
)
380+
.dy;
381+
final double page2Top = tester
382+
.getTopLeft(
383+
find.ancestor(of: find.text('Page 2'), matching: find.byType(CupertinoPageScaffold)),
384+
)
385+
.dy;
386+
final double page3Top = tester
387+
.getTopLeft(
388+
find.ancestor(of: find.text('Page 3'), matching: find.byType(CupertinoPageScaffold)),
389+
)
390+
.dy;
391+
392+
// Sheet 2 moves up above Page 1 so that the root route (Page 1) is completely hidden behind
393+
// Sheet 2.
394+
expect(page2Top, lessThanOrEqualTo(page1Top));
395+
// Sheet 3 is stacked on top of Sheet 2, with Sheet 2 peeking out above Sheet 3.
396+
expect(page2Top, lessThanOrEqualTo(page3Top));
397+
});
398+
320399
testWidgets('by default showCupertinoSheet does not enable nested navigation', (
321400
WidgetTester tester,
322401
) async {

0 commit comments

Comments
 (0)