Unverified Commit cd5936e4 authored by xubaolin's avatar xubaolin Committed by GitHub

fix a BottomSheet nullable issue (#89362)

parent abb7cf3d
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment