@@ -44,6 +44,7 @@ class BarometerStateProvider extends ChangeNotifier {
4444 bool get isRecording => _isRecording;
4545 bool get isPlayingBack => _isPlayingBack;
4646 bool get isPlaybackPaused => _isPlaybackPaused;
47+ int ? _playbackStartTimestamp;
4748
4849 StreamSubscription ? _barometerSubscription;
4950
@@ -60,10 +61,12 @@ class BarometerStateProvider extends ChangeNotifier {
6061
6162 Position ? currentPosition;
6263 StreamSubscription ? _locationStream;
64+ int _currentUpdatePeriod = 1000 ;
6365
6466 BarometerStateProvider (this ._configProvider) {
6567 _configProvider.addListener (_onConfigChanged);
6668 _currentSensorType = _configProvider.config.activeSensor;
69+ _currentUpdatePeriod = _configProvider.config.updatePeriod;
6770 }
6871
6972 Future <void > _startGeoLocationUpdates () async {
@@ -101,11 +104,16 @@ class BarometerStateProvider extends ChangeNotifier {
101104 }
102105
103106 void _onConfigChanged () {
107+ if (_isPlayingBack) return ;
108+
104109 final newSensorType = _configProvider.config.activeSensor;
105- if (_currentSensorType != newSensorType) {
106- logger
107- .d ("Sensor type changed from $_currentSensorType to $newSensorType " );
110+ final newUpdatePeriod = _configProvider.config.updatePeriod;
111+
112+ if (_currentSensorType != newSensorType ||
113+ _currentUpdatePeriod != newUpdatePeriod) {
108114 _currentSensorType = newSensorType;
115+ _currentUpdatePeriod = newUpdatePeriod;
116+
109117 _reinitializeSensors ();
110118 }
111119 }
@@ -141,14 +149,16 @@ class BarometerStateProvider extends ChangeNotifier {
141149
142150 try {
143151 _startTime = DateTime .now ().millisecondsSinceEpoch / 1000.0 ;
144- _timeTimer = Timer .periodic (const Duration (seconds: 1 ), (timer) {
145- _currentTime =
146- (DateTime .now ().millisecondsSinceEpoch / 1000.0 ) - _startTime;
147- if (_sensorAvailable) {
152+ _timeTimer = Timer .periodic (
153+ Duration (milliseconds: _currentUpdatePeriod),
154+ (timer) {
155+ _currentTime =
156+ (DateTime .now ().millisecondsSinceEpoch / 1000.0 ) - _startTime;
157+
148158 _updateData ();
149- }
150- notifyListeners ();
151- } );
159+ notifyListeners ();
160+ },
161+ );
152162
153163 if (_currentSensorType == 'In-built Sensor' ) {
154164 _initializeBuiltInSensor ();
@@ -286,7 +296,8 @@ class BarometerStateProvider extends ChangeNotifier {
286296 }
287297
288298 void startPlayback (List <List <dynamic >> data) {
289- if (data.length <= 1 ) return ;
299+ if (data.length <= 2 ) return ;
300+ _playbackStartTimestamp = int .tryParse (data[2 ][0 ].toString ())? .toInt ();
290301
291302 _isPlayingBack = true ;
292303 _isPlaybackPaused = false ;
@@ -320,7 +331,10 @@ class BarometerStateProvider extends ChangeNotifier {
320331 if (currentRow.length > 3 ) {
321332 _currentAltitude = double .tryParse (currentRow[3 ].toString ());
322333 }
323- _currentTime = (_playbackIndex - 1 ).toDouble ();
334+ final timestamp = int .tryParse (currentRow[0 ].toString ())? .toInt ();
335+ if (timestamp != null && _playbackStartTimestamp != null ) {
336+ _currentTime = (timestamp - _playbackStartTimestamp! ) / 1000.0 ;
337+ }
324338 _updateData ();
325339 _playbackIndex++ ;
326340 notifyListeners ();
@@ -364,6 +378,7 @@ class BarometerStateProvider extends ChangeNotifier {
364378 Future <void > stopPlayback () async {
365379 _isPlayingBack = false ;
366380 _isPlaybackPaused = false ;
381+ _playbackStartTimestamp = null ;
367382 _playbackTimer? .cancel ();
368383 _playbackData = null ;
369384 _playbackIndex = 0 ;
0 commit comments