mirror of
https://github.com/Iconica-Development/flutter_google_track_and_trace.git
synced 2025-05-19 05:03:45 +02:00
fix timer state change
This commit is contained in:
parent
ed11998739
commit
7e789a2789
3 changed files with 30 additions and 10 deletions
|
@ -17,7 +17,7 @@ class _TrackTraceDemoState extends State<TrackTraceDemo> {
|
|||
|
||||
@override
|
||||
void initState() {
|
||||
Timer.periodic(const Duration(seconds: 10), (_) {
|
||||
Timer.periodic(const Duration(seconds: 5), (_) {
|
||||
moveAlongRoute();
|
||||
});
|
||||
super.initState();
|
||||
|
@ -49,7 +49,7 @@ class _TrackTraceDemoState extends State<TrackTraceDemo> {
|
|||
line: const Polyline(
|
||||
polylineId: PolylineId('test route'),
|
||||
color: Colors.purple,
|
||||
width: 7,
|
||||
width: 5,
|
||||
),
|
||||
onMapCreated: (ctr) => {
|
||||
controller = ctr,
|
||||
|
|
|
@ -36,21 +36,39 @@ class TrackTraceController extends ChangeNotifier {
|
|||
}
|
||||
|
||||
GoogleMapController? get mapController => _mapController;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_mapController?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class TrackTraceRoute {
|
||||
/// route duration in seconds
|
||||
int duration = 0;
|
||||
int _duration = 0;
|
||||
|
||||
/// route distance in meters
|
||||
int distance = 0;
|
||||
int _distance = 0;
|
||||
|
||||
/// route edge points
|
||||
List<PointLatLng> line;
|
||||
final List<PointLatLng> line;
|
||||
|
||||
TrackTraceRoute(
|
||||
int durationValue, int distanceValue, List<PointLatLng> lineValue)
|
||||
: duration = durationValue,
|
||||
distance = distanceValue,
|
||||
: _duration = durationValue,
|
||||
_distance = distanceValue,
|
||||
line = lineValue;
|
||||
|
||||
int get distance => _distance;
|
||||
|
||||
int get duration => _duration;
|
||||
|
||||
set distance(int distance) {
|
||||
_distance = distance;
|
||||
}
|
||||
|
||||
set duration(int duration) {
|
||||
_duration = duration;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,14 +167,16 @@ class _GoogleTrackTraceMapState extends State<GoogleTrackTraceMap> {
|
|||
(widget.timerPrecision == TimePrecision.everyMinute) ? 60 : 1;
|
||||
Timer.periodic(Duration(seconds: updateInterval), (timer) {
|
||||
if (controller.route != null) {
|
||||
controller.route!.duration =
|
||||
controller.route!.duration - updateInterval;
|
||||
controller.route = TrackTraceRoute(
|
||||
controller.route!.duration - updateInterval,
|
||||
controller.route!.distance,
|
||||
controller.route!.line);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void calculateRoute() async {
|
||||
void calculateRoute() async {
|
||||
DirectionsRepository() //TODO refactor this away
|
||||
.getDirections(
|
||||
origin: controller.start.position,
|
||||
|
|
Loading…
Reference in a new issue