startListening method
Starts listening to accerelometer events
Implementation
void startListening() {
streamSubscription = accelerometerEvents.listen((AccelerometerEvent event) {
var now = DateTime.now().millisecondsSinceEpoch;
if ((now - _lastTime) > shakeTimeMS) {
double x = event.x;
double y = event.y;
double z = event.z;
double acceleration = sqrt(x * x + y * y + z * z) - 9.8;
if (acceleration > shakeThresholdGravity) {
if (shouldVibrate) Vibration.vibrate(duration: vibrateDuration);
_lastTime = now;
onPhoneShaken();
}
}
});
}