calculatePitch static method

double calculatePitch({
  1. required Vector3 gravity,
  2. required NativeDeviceOrientation orientation,
})

Implementation

static double calculatePitch({
  required Vector3 gravity,
  required NativeDeviceOrientation orientation,
}) {
  double pitch = 0;
  if (orientation == NativeDeviceOrientation.portraitDown) {
    pitch = atan2(-gravity.y, gravity.z);
  } else if (orientation == NativeDeviceOrientation.landscapeLeft) {
    pitch = atan2(gravity.x, gravity.z);
  } else if (orientation == NativeDeviceOrientation.landscapeRight) {
    pitch = atan2(-gravity.x, gravity.z);
  } else {
    pitch = atan2(gravity.y, gravity.z);
  }
  pitch = pitch.toDegrees;
  pitch += 90;
  if (pitch > 180) {
    pitch -= 360;
  }
  return pitch;
}