8

The Flutter map recenter button not working

dependency version = google_maps_flutter: ^2.1.6

Implement code

Future<void> _goToTheLake() async {
LatLng lat = LatLng(ctrl.getLat().value, ctrl.getLang().value);
print(lat);
final GoogleMapController controller = await _controller.future;
controller.animateCamera(
    CameraUpdate.newCameraPosition(
    CameraPosition(target: lat, zoom: 15.0)));
setState(() {});

}

E/flutter (15144): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method camera#animate on channel plugins.flutter.io/google_maps_0)
E/flutter (15144): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
E/flutter (15144): <asynchronous suspension>

enter image description here

if anyone has a solution please drop a comment.

Hamed
  • 5,867
  • 4
  • 32
  • 56
Manoj Jaiswal
  • 91
  • 1
  • 4

3 Answers3

3
  ///map controller
  Completer<GoogleMapController> mapController = Completer();

  ///create map controller
  void onMapCreated(GoogleMapController controller) {
    if(!mapController.isCompleted){
      mapController.complete(controller);
    }
  }

  @override
  void dispose() {
    mapController = Completer();
    super.dispose();
  }

here's works fine for me

DHANESH P
  • 51
  • 5
  • This helped me solve my issue. To add context I had a map in showModalBottomSheet popup. I received the following warning in debug: Unhandled Exception: Bad state: Future already completed The future had already completed in the code below when I tried to invoke the showModalBottomSheet again: final GoogleMapController animateController = await _controllerPopupMap.future; So within my GoogleMap .whenComplete method, I had to re-initialize the Completer. .whenComplete(() { _controllerPopupMap = Completer(); }); – Mabz Mar 21 '23 at 17:38
0

Hope this helps

  Completer<GoogleMapController> _controller = Completer();


    if(!freezeMap) {
      _controller.future.then((value) =>

          value.animateCamera(
              CameraUpdate.newLatLngZoom(
                  LatLng(loc.lat, loc.long), zoomLevel)));
    }
Kobi
  • 127
  • 1
  • 11
-1
dependency version = google_maps_flutter:

Leave your dependency like this. Then save it if it's still not working go through these steps:

In terminal:

flutter clean

flutter pub get

flutter run
Tyler2P
  • 2,324
  • 26
  • 22
  • 31