I've wrapped up PageView widget inside a Listener widget. There I check in onPointerSignal property if pointerSignal is PointerScrollEvent to detect if the user used the mouse wheel to scroll on the widget. Then instead of doing the weird behaviour it produces I animateToPage and I set physics property of the PageView to NeverScrollableScrollPhysics() so it does not interfere with animateToPage transition.
That is working really cool! It jumps from one page to another with a smooth animation by moving mouse wheel.
But fun comes when testing the behaviour through widget testing. Does someone know how to emit/dispatch a PointerScrollEvent? I've tried the following without any success.
void main() {
testWidgets(
'when mouse wheel moved forward then next page is shown',
(WidgetTester tester) async {
await tester.pumpWidget(
Test(
child: PointerAwarePageView(
children: [
Text('1'),
Text('2'),
],
),
),
);
expect(find.text('1'), findsOneWidget);
tester.dispatchEvent(
PointerScrollEvent(scrollDelta: Offset(0.0, 1.0)),
HitTestResult(),
);
await tester.pump(Duration(seconds: 3));
expect(find.text('2'), findsOneWidget);
},
);
}
WidgetTesterallows me to fire aPointerScrollEvent