fix a BottomSheet nullable issue (#89362)

This commit is contained in:
xubaolin 2021-10-09 17:53:03 +08:00 committed by GitHub
parent abb7cf3d66
commit cd5936e41d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -215,14 +215,22 @@ class _BottomSheetState extends State<BottomSheet> {
}
void _handleDragUpdate(DragUpdateDetails details) {
assert(widget.enableDrag);
assert(
widget.enableDrag && widget.animationController != null,
"'BottomSheet.animationController' can not be null when 'BottomSheet.enableDrag' is true. "
"Use 'BottomSheet.createAnimationController' to create one, or provide another AnimationController.",
);
if (_dismissUnderway)
return;
widget.animationController!.value -= details.primaryDelta! / _childHeight;
}
void _handleDragEnd(DragEndDetails details) {
assert(widget.enableDrag);
assert(
widget.enableDrag && widget.animationController != null,
"'BottomSheet.animationController' can not be null when 'BottomSheet.enableDrag' is true. "
"Use 'BottomSheet.createAnimationController' to create one, or provide another AnimationController.",
);
if (_dismissUnderway)
return;
bool isClosing = false;

View File

@ -23,6 +23,26 @@ void main() {
expect(dyDelta1, isNot(moreOrLessEquals(dyDelta2, epsilon: 0.1)));
}
testWidgets('Throw if enable drag without an animation controller', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/89168
await tester.pumpWidget(
MaterialApp(
home: BottomSheet(
onClosing: () {},
builder: (_) => Container(
height: 200,
color: Colors.red,
child: const Text('BottomSheet'),
),
),
),
);
await tester.drag(find.text('BottomSheet'), const Offset(0.0, 150.0));
expect(tester.takeException(), isNotNull);
});
testWidgets('Tapping on a modal BottomSheet should not dismiss it', (WidgetTester tester) async {
late BuildContext savedContext;