initialize method

  1. @override
Future<void> initialize()
override

Implementation

@override
Future<void> initialize() async {
  Scripts.load();

  _isSafariMobile =
      web.window.callMethod<JSBoolean>('isSafariMobile'.toJS).toDart;

  _isGyroscopeApiAvailable =
      web.window.callMethod<JSBoolean>('isGyroscopeApiAvailable'.toJS).toDart;
  _isDeviceMotionApiAvailable = web.window
      .callMethod<JSBoolean>('isDeviceMotionApiAvailable'.toJS)
      .toDart;

  if (_isDeviceMotionApiAvailable) {
    // If a permission is required to access the DeviceMotionEvents, we are sure there is a gyroscope on the device.
    _isPermissionRequired = web.window
        .callMethod<JSBoolean>('requiresDeviceMotionEventPermission'.toJS)
        .toDart;

    if (_isPermissionRequired) {
      _isPermissionGranted = await evaluatePermission as bool? ?? false;
    }
  }

  _isGyroscopeAvailable = _isGyroscopeApiAvailable ||
      _isDeviceMotionApiAvailable ||
      _isPermissionRequired;

  return;
}