HomeiOS Developmentandroid - sensors_plus on iOS would not pay attention the occasion or...

android – sensors_plus on iOS would not pay attention the occasion or throw an error


Im utilizing sensors_plus 6.1.1 for each android and ios, on Android all is sweet however on iOS it doesnt work the listener simply would not pay attention the occasion and it additionally doesnt has any error

 class AppStepsTracker with ChangeNotifier {
  StreamSubscription? _streamSubscriptions;

  int _steps = 0;

  String? _error;

  int get steps => _steps;
  String? get error => _error;

  void provoke() {
    _error = null;
    _streamSubscriptions = userAccelerometerEventStream().pay attention(
      _stepsCalculator,
      onError: (e) {
        _error="$e";
        notifyListeners();
      },
      cancelOnError: true,
    );
  }

  void shut() {
    _error = null;
    _steps = 0;
    _streamSubscriptions?.cancel();
    dev.log('AppStepsTracker() has been closed');
  }

  closing double incrementStepsThreeshold = 90;

  double _x = 0.0;

  double _y = 0.0;

  double _z = 0.0;

  double _distance = 0.0;

  double _tmpSteps = 0.0;

  void _stepsCalculator(
    UserAccelerometerEvent snapshot,
  ) {
    _x = snapshot.x;
    _y = snapshot.y;
    _z = snapshot.z;
    _distance = _getValue(_x, _y, _z);

    if (_distance > 1) {
      _tmpSteps++;
    }

    if (_tmpSteps > incrementStepsThreeshold) {
      _steps++;
      _tmpSteps = 0;
    }

    notifyListeners();
  }

  double _getValue(double x, double y, double z) {
    closing double magnitude = sqrt(x * x + y * y + z * z);

    return magnitude;
  }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments