@@ -26,6 +26,7 @@ import 'package:flutter/material.dart';
2626import 'shared.dart' ;
2727
2828void main () {
29+ final mapTypeVariants = getMapTypeVariants ();
2930 CameraPosition expectedPosition = const CameraPosition ();
3031 Completer <void > cameraMoveStartedCompleter = Completer <void >();
3132 Completer <void > cameraMoveCompleter = Completer <void >();
@@ -36,6 +37,7 @@ void main() {
3637 bool ? followingMyLocationActive;
3738 CameraPosition ? startedFollowingMyLocationPosition;
3839 CameraPosition ? stoppedFollowingMyLocationPosition;
40+ const double latLngTestThreshold = 0.03 ;
3941
4042 /// Define the camera event callback functions.
4143 void onCameraMoveStarted (CameraPosition position, bool gesture) {
@@ -119,10 +121,10 @@ void main() {
119121 bool checkCoordinatesMatch (CameraPosition receivedPosition) {
120122 return (receivedPosition.target.latitude - expectedPosition.target.latitude)
121123 .abs () <=
122- 0.02 &&
124+ latLngTestThreshold &&
123125 (receivedPosition.target.longitude - expectedPosition.target.longitude)
124126 .abs () <=
125- 0.02 ;
127+ latLngTestThreshold ;
126128 }
127129
128130 /// Wait for cameraMoveStarted, cameraMove and cameraIdle events.
@@ -139,8 +141,10 @@ void main() {
139141 /// Check the camera coordinates match each other within tolerance.
140142 void checkCameraCoordinatesMatch (
141143 CameraPosition received, CameraPosition expected) {
142- expect (received.target.latitude, closeTo (expected.target.latitude, 0.02 ));
143- expect (received.target.longitude, closeTo (expected.target.longitude, 0.02 ));
144+ expect (received.target.latitude,
145+ closeTo (expected.target.latitude, latLngTestThreshold));
146+ expect (received.target.longitude,
147+ closeTo (expected.target.longitude, latLngTestThreshold));
144148 }
145149
146150 patrol ('Test camera modes' , (PatrolIntegrationTester $) async {
@@ -455,17 +459,44 @@ void main() {
455459 patrol (
456460 'Test moveCamera() and animateCamera() with various options' ,
457461 (PatrolIntegrationTester $) async {
458- /// Initialize navigation with the event listener functions.
459- final GoogleNavigationViewController controller = await startNavigation (
462+ const double startLat = startLocationLat + 1 ;
463+ const double startLng = startLocationLng + 1 ;
464+ const LatLng target =
465+ LatLng (latitude: startLat + 1 , longitude: startLng + 1 );
466+
467+ final CameraUpdate start =
468+ CameraUpdate .newCameraPosition (const CameraPosition (
469+ target: LatLng (
470+ latitude: startLat,
471+ longitude: startLng,
472+ ),
473+ zoom: 9 ,
474+ ));
475+
476+ /// Initialize view with the event listener functions.
477+ final GoogleMapViewController viewController =
478+ await getMapViewControllerForTestMapType (
460479 $,
480+ testMapType: mapTypeVariants.currentValue! ,
461481 onCameraIdle: onCameraIdle,
462482 );
463- await GoogleMapsNavigator .stopGuidance ();
483+ // Move camera back to the start.
484+ Future <void > moveCameraToStart () async {
485+ resetCameraEventCompleters ();
486+ await viewController.moveCamera (start);
487+ await cameraIdleCompleter.future.timeout (const Duration (seconds: 10 ),
488+ onTimeout: () {
489+ fail ('Future timed out' );
490+ });
491+ }
492+
493+ // Move camera to the start position.
494+ await moveCameraToStart ();
464495
465496 // Create a wrapper for moveCamera() that waits until the move is finished.
466497 Future <void > moveCamera (CameraUpdate update) async {
467498 resetCameraEventCompleters ();
468- await controller .moveCamera (update);
499+ await viewController .moveCamera (update);
469500 await cameraIdleCompleter.future.timeout (const Duration (seconds: 10 ),
470501 onTimeout: () {
471502 fail ('Future timed out' );
@@ -484,7 +515,7 @@ void main() {
484515 }
485516
486517 // Animate camera to the set position with reduced duration.
487- await controller .animateCamera (
518+ await viewController .animateCamera (
488519 update,
489520 duration: const Duration (milliseconds: 50 ),
490521 onFinished: onFinished,
@@ -503,30 +534,6 @@ void main() {
503534 animateCamera
504535 ];
505536
506- const double startLat = startLocationLat + 1 ;
507- const double startLng = startLocationLng + 1 ;
508- const LatLng target =
509- LatLng (latitude: startLat + 1 , longitude: startLng + 1 );
510-
511- final CameraUpdate start =
512- CameraUpdate .newCameraPosition (const CameraPosition (
513- target: LatLng (
514- latitude: startLat,
515- longitude: startLng,
516- ),
517- zoom: 9 ,
518- ));
519-
520- // Move camera back to the start.
521- Future <void > moveCameraToStart () async {
522- resetCameraEventCompleters ();
523- await controller.moveCamera (start);
524- await cameraIdleCompleter.future.timeout (const Duration (seconds: 10 ),
525- onTimeout: () {
526- fail ('Future timed out' );
527- });
528- }
529-
530537 final CameraUpdate updateCameraPosition =
531538 CameraUpdate .newCameraPosition (const CameraPosition (
532539 bearing: 5 ,
@@ -562,9 +569,9 @@ void main() {
562569
563570 // Test that the camera target matches the provided target.
564571 expect (cameraIdlePosition.target.latitude,
565- closeTo (updateNewLatLng.latLng! .latitude, 0.02 ));
572+ closeTo (updateNewLatLng.latLng! .latitude, latLngTestThreshold ));
566573 expect (cameraIdlePosition.target.longitude,
567- closeTo (updateNewLatLng.latLng! .longitude, 0.02 ));
574+ closeTo (updateNewLatLng.latLng! .longitude, latLngTestThreshold ));
568575
569576 // Test that the other values haven't changed
570577 expect (cameraIdlePosition.bearing,
@@ -591,10 +598,14 @@ void main() {
591598 await cameraMethod (updateLatLngBounds);
592599
593600 // Test that the camera target matches the centre of the LatLngBounds.
594- expect (cameraIdlePosition.target.latitude,
595- closeTo (updateLatLngBounds.bounds! .center.latitude, 0.02 ));
596- expect (cameraIdlePosition.target.longitude,
597- closeTo (updateLatLngBounds.bounds! .center.longitude, 0.02 ));
601+ expect (
602+ cameraIdlePosition.target.latitude,
603+ closeTo (updateLatLngBounds.bounds! .center.latitude,
604+ latLngTestThreshold));
605+ expect (
606+ cameraIdlePosition.target.longitude,
607+ closeTo (updateLatLngBounds.bounds! .center.longitude,
608+ latLngTestThreshold));
598609
599610 // Test that the other values, excluding zoom, haven't changed.
600611 expect (cameraIdlePosition.bearing,
@@ -614,10 +625,10 @@ void main() {
614625 await cameraMethod (updateLatLngZoom);
615626
616627 // Test that the camera target and zoom match the provided target and zoom.
617- expect (
618- cameraIdlePosition.target.latitude, closeTo (target.latitude, 0.02 ));
628+ expect (cameraIdlePosition.target.latitude,
629+ closeTo (target.latitude, latLngTestThreshold ));
619630 expect (cameraIdlePosition.target.longitude,
620- closeTo (target.longitude, 0.02 ));
631+ closeTo (target.longitude, latLngTestThreshold ));
621632 expect (cameraIdlePosition.zoom, closeTo (updateLatLngZoom.zoom! , 0.1 ));
622633
623634 // Test that the the other values haven't changed
@@ -664,9 +675,9 @@ void main() {
664675
665676 // Test that the [focus] parameter caused the camera position to change.
666677 expect (cameraIdlePosition.target.latitude,
667- isNot (closeTo (target.latitude, 0.02 )));
678+ isNot (closeTo (target.latitude, latLngTestThreshold )));
668679 expect (cameraIdlePosition.target.longitude,
669- isNot (closeTo (target.longitude, 0.02 )));
680+ isNot (closeTo (target.longitude, latLngTestThreshold )));
670681
671682 // Test that the zoom has changed to the specified value.
672683 expect (
@@ -700,10 +711,14 @@ void main() {
700711 // Test that the other values haven't changed.
701712 expect (cameraIdlePosition.bearing,
702713 closeTo (start.cameraPosition! .bearing, 0.1 ));
703- expect (cameraIdlePosition.target.latitude,
704- closeTo (start.cameraPosition! .target.latitude, 0.02 ));
705- expect (cameraIdlePosition.target.longitude,
706- closeTo (start.cameraPosition! .target.longitude, 0.02 ));
714+ expect (
715+ cameraIdlePosition.target.latitude,
716+ closeTo (
717+ start.cameraPosition! .target.latitude, latLngTestThreshold));
718+ expect (
719+ cameraIdlePosition.target.longitude,
720+ closeTo (
721+ start.cameraPosition! .target.longitude, latLngTestThreshold));
707722 expect (
708723 cameraIdlePosition.tilt, closeTo (start.cameraPosition! .tilt, 0.1 ));
709724
@@ -726,10 +741,14 @@ void main() {
726741 // Test that the target and camera tilt haven't changed.
727742 expect (cameraIdlePosition.bearing,
728743 closeTo (start.cameraPosition! .bearing, 0.1 ));
729- expect (cameraIdlePosition.target.latitude,
730- closeTo (start.cameraPosition! .target.latitude, 0.02 ));
731- expect (cameraIdlePosition.target.longitude,
732- closeTo (start.cameraPosition! .target.longitude, 0.02 ));
744+ expect (
745+ cameraIdlePosition.target.latitude,
746+ closeTo (
747+ start.cameraPosition! .target.latitude, latLngTestThreshold));
748+ expect (
749+ cameraIdlePosition.target.longitude,
750+ closeTo (
751+ start.cameraPosition! .target.longitude, latLngTestThreshold));
733752 expect (
734753 cameraIdlePosition.tilt, closeTo (start.cameraPosition! .tilt, 0.1 ));
735754
@@ -749,19 +768,20 @@ void main() {
749768 // Test that the target and camera tilt haven't changed.
750769 expect (cameraIdlePosition.bearing,
751770 closeTo (start.cameraPosition! .bearing, 0.1 ));
752- expect (cameraIdlePosition.target.latitude,
753- closeTo (start.cameraPosition! .target.latitude, 0.02 ));
754- expect (cameraIdlePosition.target.longitude,
755- closeTo (start.cameraPosition! .target.longitude, 0.02 ));
771+ expect (
772+ cameraIdlePosition.target.latitude,
773+ closeTo (
774+ start.cameraPosition! .target.latitude, latLngTestThreshold));
775+ expect (
776+ cameraIdlePosition.target.longitude,
777+ closeTo (
778+ start.cameraPosition! .target.longitude, latLngTestThreshold));
756779 expect (
757780 cameraIdlePosition.tilt, closeTo (start.cameraPosition! .tilt, 0.1 ));
758781
759782 await moveCameraToStart ();
760783 }
761784 },
762- // TODO(jokerttu): Fix flaky tests on Android. Sometimes camera location is
763- // read before camera is animated to the new location causing the test to
764- // fail.
765- skip: Platform .isAndroid,
785+ variant: mapTypeVariants,
766786 );
767787}
0 commit comments