aeyrium / aeyrium-sensor

A Flutter sensor plugin which provide easy access to the Pitch and Roll on Android and iOS devices.
https://aeyrium.com
MIT License
57 stars 33 forks source link

Event doesn't always cancel #8

Open lukehold opened 4 years ago

lukehold commented 4 years ago

Hi,

Great package but I'm seeing mixed results with cancelling the stream. I'm recording actions and my app grabs the pitch and roll at the start of a record session, then records events and deducts this first event from each record. I do this because the phone could be at any angle to start with and it needs to be normalised. So grabbing a first value of pitch and roll is vital, and hence I need the stream to close so it doesn't keep updating this value. I use:

_vectorStream = AeyriumSensor.sensorEvents.listen(
      (SensorEvent event) {
        if (event.pitch != null) {
          _sensorVectorOffset = Vector(event.pitch, event.roll);
          _vectorStream.cancel();
        }
      },
    );

Usually this works for the first four or five attempts and then after that it no longer closes the stream, and starts overriding this offset value.

Can you please advise what the issue is and how to close your stream consistently?

Luke