detectTouchDevice function

TouchDeviceDetection? detectTouchDevice()

Starts touch device detection. Returns the current status.

Implementation

TouchDeviceDetection? detectTouchDevice() {
  if (_detectTouchDevice == null) {
    _detectTouchDevice = TouchDeviceDetection.unknown;

    try {
      // At the 1st, it won't be null:
      assert(_detectTouchDeviceListen != null);

      _detectTouchDeviceListen!
          .add(document.body!.onTouchStart.listen(_onTouchEvent));
      _detectTouchDeviceListen!
          .add(document.body!.onTouchEnd.listen(_onTouchEvent));
      _detectTouchDeviceListen!
          .add(document.body!.onTouchMove.listen(_onTouchEvent));

      _detectTouchDevice = TouchDeviceDetection.maybe;
    } catch (e) {
      _detectTouchDevice = TouchDeviceDetection.none;
      onDetectTouchDevice.add(TouchDeviceDetection.none);
    }
  }

  return _detectTouchDevice;
}