@@ -383,6 +383,53 @@ void main() {
383383 expect (scrollGesturesEnabled, true );
384384 });
385385
386+ testWidgets ('testInitialCenterLocationAtCenter' , (WidgetTester tester) async {
387+ final Completer <GoogleMapController > mapControllerCompleter =
388+ Completer <GoogleMapController >();
389+ final Key key = GlobalKey ();
390+ await tester.pumpWidget (
391+ Directionality (
392+ textDirection: TextDirection .ltr,
393+ child: GoogleMap (
394+ key: key,
395+ initialCameraPosition: _kInitialCameraPosition,
396+ onMapCreated: (GoogleMapController controller) {
397+ mapControllerCompleter.complete (controller);
398+ },
399+ ),
400+ ),
401+ );
402+ final GoogleMapController mapController =
403+ await mapControllerCompleter.future;
404+
405+ await tester.pumpAndSettle ();
406+ // TODO(cyanglaz): Remove this after we added `mapRendered` callback, and `mapControllerCompleter.complete(controller)` above should happen
407+ // in `mapRendered`.
408+ // https://github.com/flutter/flutter/issues/54758
409+ await Future .delayed (Duration (seconds: 1 ));
410+
411+ ScreenCoordinate coordinate =
412+ await mapController.getScreenCoordinate (_kInitialCameraPosition.target);
413+ Rect rect = tester.getRect (find.byKey (key));
414+ if (Platform .isIOS) {
415+ // On iOS, the coordinate value from the GoogleMapSdk doesn't include the devicePixelRatio`.
416+ // So we don't need to do the conversion like we did below for other platforms.
417+ expect (coordinate.x, (rect.center.dx - rect.topLeft.dx).round ());
418+ expect (coordinate.y, (rect.center.dy - rect.topLeft.dy).round ());
419+ } else {
420+ expect (
421+ coordinate.x,
422+ ((rect.center.dx - rect.topLeft.dx) *
423+ tester.binding.window.devicePixelRatio)
424+ .round ());
425+ expect (
426+ coordinate.y,
427+ ((rect.center.dy - rect.topLeft.dy) *
428+ tester.binding.window.devicePixelRatio)
429+ .round ());
430+ }
431+ });
432+
386433 testWidgets ('testGetVisibleRegion' , (WidgetTester tester) async {
387434 final Key key = GlobalKey ();
388435 final LatLngBounds zeroLatLngBounds = LatLngBounds (
@@ -401,13 +448,8 @@ void main() {
401448 },
402449 ),
403450 ));
404- // We suspected a bug in the iOS Google Maps SDK caused the camera is not properly positioned at
405- // initialization. https://github.com/flutter/flutter/issues/24806
406- // This temporary workaround fix is provided while the actual fix in the Google Maps SDK is
407- // still being investigated.
408- // TODO(cyanglaz): Remove this temporary fix once the Maps SDK issue is resolved.
409- // https://github.com/flutter/flutter/issues/27550
410- await tester.pumpAndSettle (const Duration (seconds: 3 ));
451+ await tester.pumpAndSettle ();
452+
411453 final GoogleMapController mapController =
412454 await mapControllerCompleter.future;
413455
@@ -707,13 +749,11 @@ void main() {
707749
708750 final GoogleMapController controller = await controllerCompleter.future;
709751
710- // We suspected a bug in the iOS Google Maps SDK caused the camera is not properly positioned at
711- // initialization. https://github.com/flutter/flutter/issues/24806
712- // This temporary workaround fix is provided while the actual fix in the Google Maps SDK is
713- // still being investigated.
714- // TODO(cyanglaz): Remove this temporary fix once the Maps SDK issue is resolved.
715- // https://github.com/flutter/flutter/issues/27550
716- await tester.pumpAndSettle (const Duration (seconds: 3 ));
752+ await tester.pumpAndSettle ();
753+ // TODO(cyanglaz): Remove this after we added `mapRendered` callback, and `mapControllerCompleter.complete(controller)` above should happen
754+ // in `mapRendered`.
755+ // https://github.com/flutter/flutter/issues/54758
756+ await Future .delayed (Duration (seconds: 1 ));
717757
718758 final LatLngBounds visibleRegion = await controller.getVisibleRegion ();
719759 final LatLng topLeft =
@@ -744,13 +784,11 @@ void main() {
744784
745785 final GoogleMapController controller = await controllerCompleter.future;
746786
747- // We suspected a bug in the iOS Google Maps SDK caused the camera is not properly positioned at
748- // initialization. https://github.com/flutter/flutter/issues/24806
749- // This temporary workaround fix is provided while the actual fix in the Google Maps SDK is
750- // still being investigated.
751- // TODO(cyanglaz): Remove this temporary fix once the Maps SDK issue is resolved.
752- // https://github.com/flutter/flutter/issues/27550
753- await tester.pumpAndSettle (const Duration (seconds: 3 ));
787+ await tester.pumpAndSettle ();
788+ // TODO(cyanglaz): Remove this after we added `mapRendered` callback, and `mapControllerCompleter.complete(controller)` above should happen
789+ // in `mapRendered`.
790+ // https://github.com/flutter/flutter/issues/54758
791+ await Future .delayed (Duration (seconds: 1 ));
754792
755793 double zoom = await controller.getZoomLevel ();
756794 expect (zoom, _kInitialZoomLevel);
@@ -778,13 +816,11 @@ void main() {
778816 ));
779817 final GoogleMapController controller = await controllerCompleter.future;
780818
781- // We suspected a bug in the iOS Google Maps SDK caused the camera is not properly positioned at
782- // initialization. https://github.com/flutter/flutter/issues/24806
783- // This temporary workaround fix is provided while the actual fix in the Google Maps SDK is
784- // still being investigated.
785- // TODO(cyanglaz): Remove this temporary fix once the Maps SDK issue is resolved.
786- // https://github.com/flutter/flutter/issues/27550
787- await tester.pumpAndSettle (const Duration (seconds: 3 ));
819+ await tester.pumpAndSettle ();
820+ // TODO(cyanglaz): Remove this after we added `mapRendered` callback, and `mapControllerCompleter.complete(controller)` above should happen
821+ // in `mapRendered`.
822+ // https://github.com/flutter/flutter/issues/54758
823+ await Future .delayed (Duration (seconds: 1 ));
788824
789825 final LatLngBounds visibleRegion = await controller.getVisibleRegion ();
790826 final LatLng northWest = LatLng (
@@ -818,13 +854,11 @@ void main() {
818854 home: Scaffold (
819855 body: SizedBox (height: 400 , width: 400 , child: map)))));
820856
821- // We suspected a bug in the iOS Google Maps SDK caused the camera is not properly positioned at
822- // initialization. https://github.com/flutter/flutter/issues/24806
823- // This temporary workaround fix is provided while the actual fix in the Google Maps SDK is
824- // still being investigated.
825- // TODO(cyanglaz): Remove this temporary fix once the Maps SDK issue is resolved.
826- // https://github.com/flutter/flutter/issues/27550
827- await tester.pumpAndSettle (const Duration (seconds: 3 ));
857+ await tester.pumpAndSettle ();
858+ // TODO(cyanglaz): Remove this after we added `mapRendered` callback, and `mapControllerCompleter.complete(controller)` above should happen
859+ // in `mapRendered`.
860+ // https://github.com/flutter/flutter/issues/54758
861+ await Future .delayed (Duration (seconds: 1 ));
828862
829863 // Simple call to make sure that the app hasn't crashed.
830864 final LatLngBounds bounds1 = await controller.getVisibleRegion ();
0 commit comments