diff --git a/example/lib/main.dart b/example/lib/main.dart index f8bf62e..77a3b42 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -17,7 +17,7 @@ class _TrackTraceDemoState extends State { @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 { line: const Polyline( polylineId: PolylineId('test route'), color: Colors.purple, - width: 7, + width: 5, ), onMapCreated: (ctr) => { controller = ctr, diff --git a/lib/src/controller.dart b/lib/src/controller.dart index d98729d..e0ce21b 100644 --- a/lib/src/controller.dart +++ b/lib/src/controller.dart @@ -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 line; + final List line; TrackTraceRoute( int durationValue, int distanceValue, List 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; + } } diff --git a/lib/src/google_map.dart b/lib/src/google_map.dart index a145a97..c22d1ba 100644 --- a/lib/src/google_map.dart +++ b/lib/src/google_map.dart @@ -167,14 +167,16 @@ class _GoogleTrackTraceMapState extends State { (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,