fix: optimized swiping and address bar toggle on tap

This commit is contained in:
randogoth 2026-10-12 09:52:28 +03:00
parent ac998b394d
commit 0e2027c9e2
5 changed files with 466 additions and 78 deletions

View file

@ -1,3 +1,4 @@
import 'package:flutter/gestures.dart' show kLongPressTimeout;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@ -21,9 +22,11 @@ SwipeNavigator _navigator({
bool canGoBack = true,
bool canGoForward = true,
double? contentWidth,
bool swipesAnywhere = false,
}) =>
SwipeNavigator(
contentWidth: contentWidth,
swipesAnywhere: swipesAnywhere,
canGoBack: canGoBack,
canGoForward: canGoForward,
backTitle: 'Previous page',
@ -124,6 +127,50 @@ void main() {
expect(back, 1);
});
testWidgets('with swipes anywhere, a drag over the page navigates',
(tester) async {
var back = 0;
await tester.pumpWidget(_wrap(_navigator(
onBack: () => back++,
onForward: () {},
swipesAnywhere: true,
)));
// The middle of the page carries the swipe, where a margin would be.
final center = tester.getCenter(find.byType(SwipeNavigator));
final gesture = await tester.startGesture(center);
await gesture.moveBy(const Offset(300, 0));
await tester.pump();
expect(find.text('Previous page'), findsOneWidget);
await gesture.up();
await tester.pumpAndSettle();
expect(back, 1);
});
testWidgets('a finger held long enough to select keeps its drag',
(tester) async {
var back = 0;
await tester.pumpWidget(_wrap(_navigator(
onBack: () => back++,
onForward: () {},
swipesAnywhere: true,
)));
// Sideways travel after the long-press window belongs to a selection,
// not to the walk.
final center = tester.getCenter(find.byType(SwipeNavigator));
final gesture = await tester.startGesture(center);
await gesture.moveBy(
const Offset(300, 0),
timeStamp: kLongPressTimeout + const Duration(milliseconds: 1),
);
await tester.pump();
expect(find.text('Previous page'), findsNothing);
await gesture.up();
await tester.pumpAndSettle();
expect(back, 0);
});
testWidgets('drags over the content column still belong to selection',
(tester) async {
var back = 0;