fix a BottomSheet nullable issue (#89362)
This commit is contained in:
parent
abb7cf3d66
commit
cd5936e41d
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user