import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
class BottomSheetScrollEvent extends StatefulWidget {
const BottomSheetScrollEvent({Key key}) : super(key: key);
@override
_BottomSheetScrollEventState createState() => _BottomSheetScrollEventState();
}
class _BottomSheetScrollEventState extends State<BottomSheetScrollEvent> {
ScrollController _scrollController = ScrollController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("底部弹窗和listview手势冲突"),
),
body: _buildBody(),
);
}
Widget _buildBody() {
bool isOutScroll = false;
return customGestureDetector(
onDown: (event) {
print("onDown");
},
onUpdate: (event) {
print("onUpdata event.delta.dy:${event.delta.dy}");
if (isOutScroll) {
_scrollController.position.pointerScroll(-event.delta.dy);
}
},
child: ListView(
controller: _scrollController,
children: [
GestureDetector(
onTapUp: (event) {
showBottomSheet(
context: context,
builder: (context) {
return Container(
height: 100,
color: Colors.white,
);
});
},
child: Container(
color: Colors.orangeAccent,
height: 100,
),
),
Container(
color: Colors.blue,
height: 100,
),
Container(
color: Colors.green,
height: 100,
),
Container(
color: Colors.red,
height: 100,
),
NotificationListener(
onNotification: (ScrollNotification notification) {
if (notification is OverscrollNotification &&
notification.metrics.axis == Axis.vertical) {
isOutScroll = true;
print("$isOutScroll");
} else {
isOutScroll = false;
}
print(notification);
return false;
},
child: Container(
height: 200,
child: ListView(
// physics: ClampingScrollPhysics(),
shrinkWrap: true,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.green,
height: 80,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.orangeAccent,
height: 80,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.greenAccent,
height: 80,
),
),
],
),
),
),
Container(
color: Colors.green,
height: 100,
),
Container(
color: Colors.blue,
height: 0100,
),
Container(
color: Colors.yellow,
height: 0100,
),
Container(
color: Colors.grey,
height: 0100,
),
],
),
);
}
RawGestureDetector customGestureDetector({
GestureDragDownCallback onDown,
GestureDragUpdateCallback onUpdate,
Widget child,
}) {
return RawGestureDetector(
child: child,
gestures: {
_MyVerticalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<
_MyVerticalDragGestureRecognizer>(
() => _MyVerticalDragGestureRecognizer(),
(detector) {
detector
..onUpdate = onUpdate
..onDown = onDown;
},
)
},
);
}
}
class _MyVerticalDragGestureRecognizer extends VerticalDragGestureRecognizer {
@override
void rejectGesture(int pointer) {
print("----->rejectGesture");
acceptGesture(pointer);
}
}