Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[showModalBottomSheet] fix: showModalBottomSheet does not move along keyboard #71636

Merged
merged 7 commits into from Jan 22, 2021
33 changes: 18 additions & 15 deletions packages/flutter/lib/src/material/bottom_sheet.dart
Expand Up @@ -375,21 +375,24 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {

return AnimatedBuilder(
animation: widget.route!.animation!,
child: BottomSheet(
animationController: widget.route!._animationController,
onClosing: () {
if (widget.route!.isCurrent) {
Navigator.pop(context);
}
},
builder: widget.route!.builder!,
backgroundColor: widget.backgroundColor,
elevation: widget.elevation,
shape: widget.shape,
clipBehavior: widget.clipBehavior,
enableDrag: widget.enableDrag,
onDragStart: handleDragStart,
onDragEnd: handleDragEnd,
child: Padding(
padding: MediaQuery.of(context).viewInsets,
child: BottomSheet(
animationController: widget.route!._animationController,
onClosing: () {
if (widget.route!.isCurrent) {
Navigator.pop(context);
}
},
builder: widget.route!.builder!,
backgroundColor: widget.backgroundColor,
elevation: widget.elevation,
shape: widget.shape,
clipBehavior: widget.clipBehavior,
enableDrag: widget.enableDrag,
onDragStart: handleDragStart,
onDragEnd: handleDragEnd,
),
),
builder: (BuildContext context, Widget? child) {
// Disable the initial animation when accessible navigation is on so
Expand Down
35 changes: 35 additions & 0 deletions packages/flutter/test/material/bottom_sheet_test.dart
Expand Up @@ -726,6 +726,41 @@ void main() {

expect(retrievedRouteSettings, routeSettings);
});

testWidgets('showModalBottomSheet should move along keyboard',
ZainUrRehmanKhan marked this conversation as resolved.
Show resolved Hide resolved
(WidgetTester tester) async {
late BuildContext savedContext;

//Wrapping Builder with MediaQuery for KeyboardHeight
ZainUrRehmanKhan marked this conversation as resolved.
Show resolved Hide resolved
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: const MediaQueryData(viewInsets: EdgeInsets.only(bottom: 200)),
child: Builder(
builder: (BuildContext context) {
savedContext = context;
return Container();
},
),
),
),
);

await tester.pump();
expect(find.text('BottomSheet'), findsNothing);

showModalBottomSheet<void>(
context: savedContext,
builder: (BuildContext context) {
return const Text('BottomSheet');
},
);

await tester.pumpAndSettle();

expect(find.text('BottomSheet'), findsOneWidget);
expect(tester.getBottomLeft(find.text('BottomSheet')).dy, 600);
});
}

class _TestPage extends StatelessWidget {
Expand Down