import 'package:flutter/material.dart'; import 'package:location/location.dart'; import 'package:gps/models/gps_point.dart'; import 'package:gps/utils/gps_persister.dart'; class GpsModel with ChangeNotifier { bool _recording = false; GpsPoint _currentLocation = GpsPoint(); List _recordedLocations = []; bool get isRecording => _recording; GpsPoint get currentLocation => _currentLocation; List get locations => List.unmodifiable(_recordedLocations); GpsModel(Stream stream) { stream.listen((event) { _currentLocation = GpsPoint( latitude: event.latitude ?? 0.0, longitude: event.longitude ?? 0.0, accuracy: event.accuracy ?? 0.0, speed: event.speed ?? 0.0, heading: event.heading ?? 0.0, time: event.time ?? 0.0, satelliteNumber: event.satelliteNumber ?? 0, provider: event.provider ?? "none"); if (_recording) { _recordedLocations.add(_currentLocation); } notifyListeners(); }); } void toggleRecording() { _recording = !_recording; notifyListeners(); } void save(GpsPersister s) { s.save(locations); _recordedLocations = []; } }