Search code examples
flutterdartaccelerometer

How do I get the update frequency of the accelerometer in flutter?


I am currently working with the flutter_sensors package to get the acceleration data.

How do I get or measure the update frequency of the accelerometer?

As far as I know the flutter_sensors and the sensors package doesn't provide a way of getting the frequency. Is there a better package?

I know that I can set the frequency with the flutter_sensors package but I can't trust that the data always comes at the right time or can I?


Solution

  • I choose to use the Stopwatch of the dart:core (https://api.flutter.dev/flutter/dart-core/Stopwatch-class.html).

    Every time I get new acceleration data I store the Stopwatch.elapsedMilliseconds. With this data I can calculate the frequency.