I would not use the Flutter sensors_plus
package to get yaw, roll or pitch. Even if you only wanted yaw (aka. heading or azimuth), as shown in this Github issue: MagnetometerEvent to compass values. It is challenging to convert magnetometer readings (microteslas) into roll, pitch, yaw because of the maths. You only get raw magnetometer readings.
As I wrote in the comment there:
I would highly recommend using
https://pub.dev/packages/flutter_compass, https://pub.dev/packages/motion_sensors or writing your own plugin to
use the OS APIs to get the data you need directly, instead of using
the magnetometer readings (unit: micro Teslas), to allow you to use the
operating-system calculated heading, which could use multiple
sensors (sensor fusion) to give improved accuracy based on the
hardware, as well as compensate for the location (the magnetometer
only allows you to calculate magnetic north, not true north).
motion_sensors
provides an OrientationEvent
, which contains roll, pitch and yaw, in radians.
Writing your own plugin
If you need roll or pitch (more than yaw/heading/azimuth), the OS APIs provide it:
float orientationData[] = new float[3];
SensorManager.getOrientation(R, orientationData);
azimuth = orientationData[0];
pitch = orientationData[1];
roll = orientationData[2];
CMQuaternion quat = self.motionManager.deviceMotion.attitude.quaternion;
myRoll = radiansToDegrees(atan2(2*(quat.y*quat.w - quat.x*quat.z), 1 - 2*quat.y*quat.y - 2*quat.z*quat.z)) ;
myPitch = radiansToDegrees(atan2(2*(quat.x*quat.w + quat.y*quat.z), 1 - 2*quat.x*quat.x - 2*quat.z*quat.z));
myYaw = radiansToDegrees(asin(2*quat.x*quat.y + 2*quat.w*quat.z));