import 'package:cc_ui_kit/cc_ui_kit.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { for (final axis in AxisHint.values) { for (final cancel in [false, true]) { testWidgets( '$axis extra finger ${cancel ? 'cancel' : 'release'} stays stopped', (tester) async { var drive = 0; var stops = 0; await tester.pumpWidget( MaterialApp( home: Center( child: CCJoystick( axisHint: axis, onValueChanged: (value) => drive = axis == AxisHint.forwardBackward ? value.y : value.x, onPanEnd: () async { drive = 0; stops++; }, ), ), ), ); final center = tester.getCenter(find.byType(CCJoystick)); final direction = axis == AxisHint.forwardBackward ? const Offset(0, -1) : const Offset(1, 0); final first = await tester.startGesture(center, pointer: 1); await first.moveBy(direction * 30); await first.moveBy(direction * 20); await tester.pump(); expect(drive, greaterThan(0)); final second = await tester.startGesture(center, pointer: 2); if (cancel) { await second.cancel(); } else { await second.up(); } await tester.pump(); expect(drive, 0); await first.moveBy(direction * 20); await tester.pump(); expect( drive, 0, reason: 'ended interaction must ignore remaining moves', ); await first.up(); await tester.pump(const Duration(seconds: 1)); expect(stops, greaterThan(0)); expect( drive, 0, reason: 'released joystick must leave zero for the timer', ); expect(stops, 1, reason: 'pointer and pan end must not stop twice'); // A new gesture must still work after the interrupted interaction. final next = await tester.startGesture(center, pointer: 3); await next.moveBy(direction * 30); await next.moveBy(direction * 20); await tester.pump(); expect(drive, greaterThan(0)); await next.up(); await tester.pump(const Duration(seconds: 1)); expect(drive, 0); expect(stops, 2); await tester.pumpWidget(const SizedBox.shrink()); }, ); } } }