Skip to content

Commit 6c6dbb2

Browse files
rkishan516mboetger
authored andcommitted
Fix: Update sheet route bottom padding with top padding (flutter#164473)
Fix: Update sheet route bottom padding with top padding fixes: flutter#163572 fixes: flutter#164087 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
1 parent 0346be5 commit 6c6dbb2

File tree

2 files changed

+103
-14
lines changed

2 files changed

+103
-14
lines changed

packages/flutter/lib/src/cupertino/sheet.dart

+11-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const double _kTopGapRatio = 0.08;
3535
// the top of the screen. Values found from eyeballing a simulator running iOS 18.0.
3636
final Animatable<Offset> _kBottomUpTween = Tween<Offset>(
3737
begin: const Offset(0.0, 1.0),
38-
end: const Offset(0.0, _kTopGapRatio),
38+
end: Offset.zero,
3939
);
4040

4141
// Offset change for when a new sheet covers another sheet. '0.0' represents the
@@ -427,10 +427,7 @@ class _CupertinoSheetTransitionState extends State<CupertinoSheetTransition> {
427427
scale: _secondaryScaleAnimation,
428428
filterQuality: FilterQuality.medium,
429429
alignment: Alignment.topCenter,
430-
child: ClipRRect(
431-
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
432-
child: child,
433-
),
430+
child: child,
434431
),
435432
);
436433
}
@@ -444,10 +441,7 @@ class _CupertinoSheetTransitionState extends State<CupertinoSheetTransition> {
444441
context,
445442
widget.primaryRouteAnimation,
446443
widget.linearTransition,
447-
ClipRRect(
448-
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
449-
child: widget.child,
450-
),
444+
widget.child,
451445
),
452446
),
453447
);
@@ -498,16 +492,19 @@ class CupertinoSheetRoute<T> extends PageRoute<T> with _CupertinoSheetRouteTrans
498492

499493
@override
500494
Widget buildContent(BuildContext context) {
501-
final double bottomPadding = MediaQuery.sizeOf(context).height * _kTopGapRatio;
495+
final double topPadding = MediaQuery.sizeOf(context).height * _kTopGapRatio;
502496
return MediaQuery.removePadding(
503497
context: context,
504498
removeTop: true,
505499
removeBottom: true,
506500
child: Padding(
507-
padding: EdgeInsets.only(bottom: bottomPadding),
508-
child: CupertinoUserInterfaceLevel(
509-
data: CupertinoUserInterfaceLevelData.elevated,
510-
child: _CupertinoSheetScope(child: builder(context)),
501+
padding: EdgeInsets.only(top: topPadding),
502+
child: ClipRRect(
503+
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
504+
child: CupertinoUserInterfaceLevel(
505+
data: CupertinoUserInterfaceLevelData.elevated,
506+
child: _CupertinoSheetScope(child: builder(context)),
507+
),
511508
),
512509
),
513510
);

packages/flutter/test/cupertino/sheet_test.dart

+92
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,98 @@ void main() {
12121212
expect(finalPosition, equals(middlePosition));
12131213
expect(finalPosition, equals(initialPosition));
12141214
});
1215+
1216+
// Regression test for https://github.com/flutter/flutter/issues/163572.
1217+
testWidgets('showCupertinoSheet shows snackbar at bottom of screen', (
1218+
WidgetTester tester,
1219+
) async {
1220+
final GlobalKey<ScaffoldMessengerState> scaffoldKey = GlobalKey<ScaffoldMessengerState>();
1221+
1222+
void showSheet(BuildContext context) {
1223+
showCupertinoSheet<void>(
1224+
context: context,
1225+
pageBuilder: (BuildContext context) {
1226+
return Scaffold(
1227+
body: Column(
1228+
children: <Widget>[
1229+
const Text('Cupertino Sheet'),
1230+
CupertinoButton(
1231+
onPressed: () {
1232+
scaffoldKey.currentState?.showSnackBar(
1233+
const SnackBar(content: Text('SnackBar'), backgroundColor: Colors.red),
1234+
);
1235+
},
1236+
child: const Text('Show SnackBar'),
1237+
),
1238+
],
1239+
),
1240+
);
1241+
},
1242+
);
1243+
}
1244+
1245+
await tester.pumpWidget(
1246+
MaterialApp(
1247+
scaffoldMessengerKey: scaffoldKey,
1248+
home: Scaffold(
1249+
body: Center(
1250+
child: Column(
1251+
children: <Widget>[
1252+
const Text('Page 1'),
1253+
Builder(
1254+
builder: (BuildContext context) {
1255+
return CupertinoButton(
1256+
onPressed: () {
1257+
showSheet(context);
1258+
},
1259+
child: const Text('Show Cupertino Sheet'),
1260+
);
1261+
},
1262+
),
1263+
],
1264+
),
1265+
),
1266+
),
1267+
),
1268+
);
1269+
1270+
expect(find.text('Page 1'), findsOneWidget);
1271+
1272+
await tester.tap(find.text('Show Cupertino Sheet'));
1273+
await tester.pumpAndSettle();
1274+
1275+
expect(
1276+
tester
1277+
.getTopLeft(
1278+
find.ancestor(of: find.text('Cupertino Sheet'), matching: find.byType(Scaffold)),
1279+
)
1280+
.dy,
1281+
greaterThan(0.0),
1282+
);
1283+
1284+
await tester.tap(find.text('Show SnackBar'));
1285+
await tester.pumpAndSettle();
1286+
1287+
expect(find.byType(SnackBar), findsAtLeast(1));
1288+
expect(
1289+
tester.getBottomLeft(find.byType(Scaffold).first).dy,
1290+
equals(tester.getBottomLeft(find.byType(SnackBar).first).dy),
1291+
);
1292+
1293+
final TestGesture gesture = await tester.startGesture(const Offset(200, 400));
1294+
await tester.pump();
1295+
expect(
1296+
tester.getBottomLeft(find.byType(Scaffold).first).dy,
1297+
equals(tester.getBottomLeft(find.byType(SnackBar).first).dy),
1298+
);
1299+
1300+
await gesture.up();
1301+
await tester.pumpAndSettle();
1302+
expect(
1303+
tester.getBottomLeft(find.byType(Scaffold).first).dy,
1304+
equals(tester.getBottomLeft(find.byType(SnackBar).first).dy),
1305+
);
1306+
});
12151307
});
12161308

12171309
testWidgets('CupertinoSheetTransition handles SystemUiOverlayStyle changes', (

0 commit comments

Comments
 (0)