Getting device orientation (yaw, roll and pitch) in Flutter

南笙酒味 提交于 2019-12-24 10:35:45

问题


In Android I can get the device yaw, roll and pitch using a GAME_ROTATION_VECTOR sensor.

I need to do the same thing in Flutter, but I haven't been able to find anything but the sensors package, which only gives access to accelerometer & gyroscope sensors.

What can I do? Do I need to calculate the orientation myself from the accelerometer and gyro?


回答1:


Don't know if this is still relevant, as the question wasn't closed, but for those seeking the answer... there is now a Flutter Sensors package which does all the magic for you.

You'll have to subscribe to the streams to get the current values of the accelerometers and gyroscopes, of course.

For example:

  @override
  void initState() {
    super.initState();
    _streamSubscriptions
        .add(accelerometerEvents.listen((AccelerometerEvent event) {
      setState(() {
        _accelerometerValues = <double>[event.x, event.y, event.z];
      });
    }));
    _streamSubscriptions.add(gyroscopeEvents.listen((GyroscopeEvent event) {
      setState(() {
        _gyroscopeValues = <double>[event.x, event.y, event.z];
      });
    }));
    _streamSubscriptions
        .add(userAccelerometerEvents.listen((UserAccelerometerEvent event) {
      setState(() {
        _userAccelerometerValues = <double>[event.x, event.y, event.z];
      });
    }));
  }


来源:https://stackoverflow.com/questions/51749317/getting-device-orientation-yaw-roll-and-pitch-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!