mirror of
https://github.com/Iconica-Development/flutter_google_track_and_trace.git
synced 2025-05-19 13:13:44 +02:00
cancel timer once disposed
This commit is contained in:
parent
1b4746a750
commit
d82e8807d1
3 changed files with 19 additions and 11 deletions
|
@ -41,5 +41,9 @@
|
||||||
</array>
|
</array>
|
||||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||||
<false/>
|
<false/>
|
||||||
|
<key>NSCameraUsageDescription</key>
|
||||||
|
<string>This app requires access to the camera.</string>
|
||||||
|
<key>NSPhotoLibraryUsageDescription</key>
|
||||||
|
<string>This app requires access to the photo library.</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
|
@ -7,7 +7,7 @@ packages:
|
||||||
name: async
|
name: async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.8.1"
|
version: "2.8.2"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -21,7 +21,7 @@ packages:
|
||||||
name: characters
|
name: characters
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.2.0"
|
||||||
charcode:
|
charcode:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -183,7 +183,7 @@ packages:
|
||||||
name: matcher
|
name: matcher
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.10"
|
version: "0.12.11"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -272,7 +272,7 @@ packages:
|
||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.4.2"
|
version: "0.4.3"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -286,7 +286,7 @@ packages:
|
||||||
name: vector_math
|
name: vector_math
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
version: "2.1.1"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.14.0 <3.0.0"
|
dart: ">=2.14.0 <3.0.0"
|
||||||
flutter: ">=2.5.0"
|
flutter: ">=2.5.0"
|
||||||
|
|
|
@ -87,8 +87,8 @@ class _GoogleTrackTraceMapState extends State<GoogleTrackTraceMap> {
|
||||||
|
|
||||||
DateTime lastRouteUpdate = DateTime.now();
|
DateTime lastRouteUpdate = DateTime.now();
|
||||||
|
|
||||||
late final Timer routeCalculateTimer;
|
Timer? routeCalculateTimer;
|
||||||
late final Timer markerUpdateTimer;
|
Timer? markerUpdateTimer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -105,9 +105,9 @@ class _GoogleTrackTraceMapState extends State<GoogleTrackTraceMap> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
routeCalculateTimer?.cancel();
|
||||||
|
markerUpdateTimer?.cancel();
|
||||||
controller.dispose();
|
controller.dispose();
|
||||||
routeCalculateTimer.cancel();
|
|
||||||
markerUpdateTimer.cancel();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +206,10 @@ class _GoogleTrackTraceMapState extends State<GoogleTrackTraceMap> {
|
||||||
(widget.timerPrecision == TimePrecision.everyMinute) ? 60 : 1;
|
(widget.timerPrecision == TimePrecision.everyMinute) ? 60 : 1;
|
||||||
markerUpdateTimer =
|
markerUpdateTimer =
|
||||||
Timer.periodic(Duration(seconds: updateInterval), (timer) {
|
Timer.periodic(Duration(seconds: updateInterval), (timer) {
|
||||||
|
if (mounted) {
|
||||||
|
timer.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (controller.route != null) {
|
if (controller.route != null) {
|
||||||
checkDestinationCloseBy();
|
checkDestinationCloseBy();
|
||||||
controller.route = TrackTraceRoute(
|
controller.route = TrackTraceRoute(
|
||||||
|
@ -252,8 +256,8 @@ class _GoogleTrackTraceMapState extends State<GoogleTrackTraceMap> {
|
||||||
controller.end.position,
|
controller.end.position,
|
||||||
) <
|
) <
|
||||||
widget.markerUpdatePrecision) {
|
widget.markerUpdatePrecision) {
|
||||||
routeCalculateTimer.cancel();
|
routeCalculateTimer?.cancel();
|
||||||
markerUpdateTimer.cancel();
|
markerUpdateTimer?.cancel();
|
||||||
if (controller.route != null) {
|
if (controller.route != null) {
|
||||||
controller.route!.line = <PointLatLng>[controller.route!.line[1]];
|
controller.route!.line = <PointLatLng>[controller.route!.line[1]];
|
||||||
controller.route!.distance = 0;
|
controller.route!.distance = 0;
|
||||||
|
|
Loading…
Reference in a new issue