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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
Timer.periodic(const Duration(seconds: 10), (_) {
|
Timer.periodic(const Duration(seconds: 5), (_) {
|
||||||
moveAlongRoute();
|
moveAlongRoute();
|
||||||
});
|
});
|
||||||
super.initState();
|
super.initState();
|
||||||
|
@ -49,7 +49,7 @@ class _TrackTraceDemoState extends State<TrackTraceDemo> {
|
||||||
line: const Polyline(
|
line: const Polyline(
|
||||||
polylineId: PolylineId('test route'),
|
polylineId: PolylineId('test route'),
|
||||||
color: Colors.purple,
|
color: Colors.purple,
|
||||||
width: 7,
|
width: 5,
|
||||||
),
|
),
|
||||||
onMapCreated: (ctr) => {
|
onMapCreated: (ctr) => {
|
||||||
controller = ctr,
|
controller = ctr,
|
||||||
|
|
|
@ -36,21 +36,39 @@ class TrackTraceController extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
GoogleMapController? get mapController => _mapController;
|
GoogleMapController? get mapController => _mapController;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_mapController?.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TrackTraceRoute {
|
class TrackTraceRoute {
|
||||||
/// route duration in seconds
|
/// route duration in seconds
|
||||||
int duration = 0;
|
int _duration = 0;
|
||||||
|
|
||||||
/// route distance in meters
|
/// route distance in meters
|
||||||
int distance = 0;
|
int _distance = 0;
|
||||||
|
|
||||||
/// route edge points
|
/// route edge points
|
||||||
List<PointLatLng> line;
|
final List<PointLatLng> line;
|
||||||
|
|
||||||
TrackTraceRoute(
|
TrackTraceRoute(
|
||||||
int durationValue, int distanceValue, List<PointLatLng> lineValue)
|
int durationValue, int distanceValue, List<PointLatLng> lineValue)
|
||||||
: duration = durationValue,
|
: _duration = durationValue,
|
||||||
distance = distanceValue,
|
_distance = distanceValue,
|
||||||
line = lineValue;
|
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;
|
(widget.timerPrecision == TimePrecision.everyMinute) ? 60 : 1;
|
||||||
Timer.periodic(Duration(seconds: updateInterval), (timer) {
|
Timer.periodic(Duration(seconds: updateInterval), (timer) {
|
||||||
if (controller.route != null) {
|
if (controller.route != null) {
|
||||||
controller.route!.duration =
|
controller.route = TrackTraceRoute(
|
||||||
controller.route!.duration - updateInterval;
|
controller.route!.duration - updateInterval,
|
||||||
|
controller.route!.distance,
|
||||||
|
controller.route!.line);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void calculateRoute() async {
|
void calculateRoute() async {
|
||||||
DirectionsRepository() //TODO refactor this away
|
DirectionsRepository() //TODO refactor this away
|
||||||
.getDirections(
|
.getDirections(
|
||||||
origin: controller.start.position,
|
origin: controller.start.position,
|
||||||
|
|
Loading…
Reference in a new issue