Migrate to FlutterView.gestureSettings (#121749)
This commit is contained in:
committed by
GitHub
parent
5cf1e5f773
commit
92a1a8ba09
@@ -26,7 +26,7 @@ class DeviceGestureSettings {
|
||||
|
||||
/// Create a new [DeviceGestureSettings] from the provided [view].
|
||||
factory DeviceGestureSettings.fromView(ui.FlutterView view) {
|
||||
final double? physicalTouchSlop = view.viewConfiguration.gestureSettings.physicalTouchSlop;
|
||||
final double? physicalTouchSlop = view.gestureSettings.physicalTouchSlop;
|
||||
return DeviceGestureSettings(
|
||||
touchSlop: physicalTouchSlop == null ? null : physicalTouchSlop / view.devicePixelRatio
|
||||
);
|
||||
|
||||
@@ -90,9 +90,7 @@ class NestedDraggableCase extends StatelessWidget {
|
||||
|
||||
void main() {
|
||||
testWidgets('Scroll Views get the same ScrollConfiguration as GestureDetectors', (WidgetTester tester) async {
|
||||
tester.binding.window.viewConfigurationTestValue = const ui.ViewConfiguration(
|
||||
gestureSettings: ui.GestureSettings(physicalTouchSlop: 4),
|
||||
);
|
||||
tester.binding.window.gestureSettingsTestValue = const ui.GestureSettings(physicalTouchSlop: 4);
|
||||
final TestResult result = TestResult();
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
@@ -110,12 +108,12 @@ void main() {
|
||||
|
||||
expect(result.dragStarted, true);
|
||||
expect(result.dragUpdate, true);
|
||||
tester.binding.window.clearGestureSettingsTestValue();
|
||||
});
|
||||
|
||||
testWidgets('Scroll Views get the same ScrollConfiguration as Draggables', (WidgetTester tester) async {
|
||||
tester.binding.window.viewConfigurationTestValue = const ui.ViewConfiguration(
|
||||
gestureSettings: ui.GestureSettings(physicalTouchSlop: 4),
|
||||
);
|
||||
tester.binding.window.gestureSettingsTestValue = const ui.GestureSettings(physicalTouchSlop: 4);
|
||||
|
||||
final TestResult result = TestResult();
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
@@ -133,5 +131,6 @@ void main() {
|
||||
|
||||
expect(result.dragStarted, true);
|
||||
expect(result.dragUpdate, true);
|
||||
tester.binding.window.clearGestureSettingsTestValue();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1326,12 +1326,10 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('MediaQueryData.gestureSettings is set from window.viewConfiguration', (WidgetTester tester) async {
|
||||
tester.binding.window.viewConfigurationTestValue = const ViewConfiguration(
|
||||
gestureSettings: GestureSettings(physicalDoubleTapSlop: 100, physicalTouchSlop: 100),
|
||||
);
|
||||
tester.binding.window.gestureSettingsTestValue = const GestureSettings(physicalDoubleTapSlop: 100, physicalTouchSlop: 100);
|
||||
|
||||
expect(MediaQueryData.fromView(tester.binding.window).gestureSettings.touchSlop, closeTo(33.33, 0.1)); // Repeating, of course
|
||||
tester.binding.window.viewConfigurationTestValue = null;
|
||||
tester.binding.window.clearGestureSettingsTestValue();
|
||||
});
|
||||
|
||||
testWidgets('MediaQuery can be partially depended-on', (WidgetTester tester) async {
|
||||
@@ -1544,6 +1542,8 @@ class TestView implements FlutterView {
|
||||
final ViewConfiguration viewConfiguration = const ViewConfiguration();
|
||||
@override
|
||||
final List<DisplayFeature> displayFeatures = <DisplayFeature>[];
|
||||
@override
|
||||
final GestureSettings gestureSettings = const GestureSettings();
|
||||
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
|
||||
@@ -143,6 +143,20 @@ class TestWindow implements ui.SingletonFlutterWindow {
|
||||
onMetricsChanged?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
ui.GestureSettings get gestureSettings => _gestureSettings ?? _window.gestureSettings;
|
||||
ui.GestureSettings? _gestureSettings;
|
||||
/// Hides the real gesture settings and reports the given [gestureSettingsTestValue] instead.
|
||||
set gestureSettingsTestValue(ui.GestureSettings gestureSettingsTestValue) { // ignore: avoid_setters_without_getters
|
||||
_gestureSettings = gestureSettingsTestValue;
|
||||
onMetricsChanged?.call();
|
||||
}
|
||||
/// Deletes any existing test gesture settings and returns to using the real gesture settings.
|
||||
void clearGestureSettingsTestValue() {
|
||||
_paddingTestValue = null;
|
||||
onMetricsChanged?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
List<ui.DisplayFeature> get displayFeatures => _displayFeaturesTestValue ?? _window.displayFeatures;
|
||||
List<ui.DisplayFeature>? _displayFeaturesTestValue;
|
||||
@@ -508,6 +522,7 @@ class TestWindow implements ui.SingletonFlutterWindow {
|
||||
void clearAllTestValues() {
|
||||
clearDevicePixelRatioTestValue();
|
||||
clearPaddingTestValue();
|
||||
clearGestureSettingsTestValue();
|
||||
clearDisplayFeaturesTestValue();
|
||||
clearPhysicalSizeTestValue();
|
||||
clearViewInsetsTestValue();
|
||||
|
||||
Reference in New Issue
Block a user