gesture_settings.dart 1.69 KB
Newer Older
1 2 3 4 5
// 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;
6

7 8
import 'package:flutter/foundation.dart';

9 10
export 'dart:ui' show FlutterView;

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/// 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,
  });

27 28 29
  /// Create a new [DeviceGestureSettings] from the provided [view].
  factory DeviceGestureSettings.fromView(ui.FlutterView view) {
    final double? physicalTouchSlop = view.viewConfiguration.gestureSettings.physicalTouchSlop;
30
    return DeviceGestureSettings(
31
      touchSlop: physicalTouchSlop == null ? null : physicalTouchSlop / view.devicePixelRatio
32 33 34 35 36 37 38 39 40 41 42
    );
  }

  /// 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
43
  int get hashCode => Object.hash(touchSlop, 23);
44 45 46

  @override
  bool operator ==(Object other) {
47
    if (other.runtimeType != runtimeType) {
48
      return false;
49
    }
50 51 52 53 54 55 56
    return other is DeviceGestureSettings
      && other.touchSlop == touchSlop;
  }

  @override
  String toString() => 'DeviceGestureSettings(touchSlop: $touchSlop)';
}