@@ -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,17 @@ 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+ final intervalMs = _configProvider.config.updatePeriod;
153+ _timeTimer = Timer .periodic (
154+ Duration (milliseconds: intervalMs),
155+ (timer) {
156+ _currentTime =
157+ (DateTime .now ().millisecondsSinceEpoch / 1000.0 ) - _startTime;
158+
148159 _updateData ();
149- }
150- notifyListeners ();
151- } );
160+ notifyListeners ();
161+ },
162+ );
152163
153164 if (_currentSensorType == 'In-built Sensor' ) {
154165 _initializeBuiltInSensor ();
@@ -281,7 +292,8 @@ class BarometerStateProvider extends ChangeNotifier {
281292 }
282293
283294 void startPlayback (List <List <dynamic >> data) {
284- if (data.length <= 1 ) return ;
295+ if (data.length <= 2 ) return ;
296+ _playbackStartTimestamp = int .tryParse (data[2 ][0 ].toString ())? .toInt ();
285297
286298 _isPlayingBack = true ;
287299 _isPlaybackPaused = false ;
@@ -315,7 +327,10 @@ class BarometerStateProvider extends ChangeNotifier {
315327 if (currentRow.length > 3 ) {
316328 _currentAltitude = double .tryParse (currentRow[3 ].toString ());
317329 }
318- _currentTime = (_playbackIndex - 1 ).toDouble ();
330+ final timestamp = int .tryParse (currentRow[0 ].toString ())? .toInt ();
331+ if (timestamp != null && _playbackStartTimestamp != null ) {
332+ _currentTime = (timestamp - _playbackStartTimestamp! ) / 1000.0 ;
333+ }
319334 _updateData ();
320335 _playbackIndex++ ;
321336 notifyListeners ();
0 commit comments