/
gesture_settings.dart
56 lines (46 loc) · 1.67 KB
/
gesture_settings.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
export 'dart:ui' show FlutterView;
/// The device specific gesture settings scaled into logical pixels.
///
/// This configuration can be retrieved from the window, or more commonly from a
/// [MediaQuery] widget.
///
/// See also:
///
/// * [ui.GestureSettings], the configuration that this is derived from.
@immutable
class DeviceGestureSettings {
/// Create a new [DeviceGestureSettings] with configured settings in logical
/// pixels.
const DeviceGestureSettings({
this.touchSlop,
});
/// Create a new [DeviceGestureSettings] from the provided [view].
factory DeviceGestureSettings.fromView(ui.FlutterView view) {
final double? physicalTouchSlop = view.gestureSettings.physicalTouchSlop;
return DeviceGestureSettings(
touchSlop: physicalTouchSlop == null ? null : physicalTouchSlop / view.devicePixelRatio
);
}
/// The touch slop value in logical pixels, or `null` if it was not set.
final double? touchSlop;
/// The touch slop value for pan gestures, in logical pixels, or `null` if it
/// was not set.
double? get panSlop => touchSlop != null ? (touchSlop! * 2) : null;
@override
int get hashCode => Object.hash(touchSlop, 23);
@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType) {
return false;
}
return other is DeviceGestureSettings
&& other.touchSlop == touchSlop;
}
@override
String toString() => 'DeviceGestureSettings(touchSlop: $touchSlop)';
}