Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MissingPluginException (MissingPluginException(No implementation found for method camera#animate on channel plugins.flutter.io/google_maps_53))

i recently installed google maps in my flutter app but i keep getting this error,

MissingPluginException (MissingPluginException(No implementation found for method camera#animate on channel plugins.flutter.io/google_maps_53))

this happens on every map controller i call on, even oncreated method gives me the same problem, i first tried flutter clean and flutter pub get after but no avail, now i dont know

here is my main dart file where i create the map

GoogleMap(
   mapToolbarEnabled: false,
   mapType: MapType.normal,
   initialCameraPosition: CameraPosition(target:appState.initialPosition, zoom: 15.0),
   markers: appState.markers,
   onCameraMove: appState.onCameraMove,
   polylines: appState.polyLines,
   myLocationEnabled: true,
   zoomControlsEnabled: false,
   onMapCreated: appState.onCreated,compassEnabled: false,
   myLocationButtonEnabled: false,   
),

here is my seperate appstate.dart file

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:toladriver/requests/google_maps_requests.dart';


class AppState with ChangeNotifier {
  static LatLng _initialPosition;
  LatLng _lastPosition = _initialPosition;
  bool locationServiceActive = true;
  final Set<Marker> _markers = {};
  final Set<Polyline> _polyLines = {};
  GoogleMapController _mapController;
  GoogleMapsServices _googleMapsServices = GoogleMapsServices();
  TextEditingController locationController = TextEditingController();
  TextEditingController destinationController = TextEditingController();
  LatLng get initialPosition => _initialPosition;
  LatLng get lastPosition => _lastPosition;
  GoogleMapsServices get googleMapsServices => _googleMapsServices;
  GoogleMapController get mapController => _mapController;
  Set<Marker> get markers => _markers;
  Set<Polyline> get polyLines => _polyLines;

  AppState() {
    _getUserLocation();
    _loadingInitialPosition();
  }
// ! TO GET THE USERS LOCATION
  void _getUserLocation() async {
    print("GET USER METHOD RUNNING =========");
    Position position = await Geolocator()
        .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
    List<Placemark> placemark = await Geolocator()
        .placemarkFromCoordinates(position.latitude, position.longitude);
    _initialPosition = LatLng(position.latitude, position.longitude);
    print("the latitude is: ${position.longitude} and th longitude is: ${position.longitude} ");
    print("initial position is : ${_initialPosition.toString()}");
    locationController.text = placemark[0].name;
    notifyListeners();
  }

  // ! TO CREATE ROUTE
  void createRoute(String encondedPoly) {
    _polyLines.add(Polyline(
        polylineId: PolylineId(_lastPosition.toString()),
        width: 5,
        points: _convertToLatLng(_decodePoly(encondedPoly)),
        color: Colors.blueGrey));
    notifyListeners();
  }

  // ! ADD A MARKER ON THE MAO
  void _addMarker(LatLng location, String address) {
    _markers.add(Marker(
        markerId: MarkerId(_lastPosition.toString()),
        position: location,
        infoWindow: InfoWindow(title: address, snippet: "go here"),
        icon: BitmapDescriptor.defaultMarker));
    notifyListeners();
  }

  // ! CREATE LAGLNG LIST
  List<LatLng> _convertToLatLng(List points) {
    List<LatLng> result = <LatLng>[];
    for (int i = 0; i < points.length; i++) {
      if (i % 2 != 0) {
        result.add(LatLng(points[i - 1], points[i]));
      }
    }
    return result;
  }

  // !DECODE POLY
  List _decodePoly(String poly) {
    var list = poly.codeUnits;
    var lList = new List();
    int index = 0;
    int len = poly.length;
    int c = 0;
// repeating until all attributes are decoded
    do {
      var shift = 0;
      int result = 0;

      // for decoding value of one attribute
      do {
        c = list[index] - 63;
        result |= (c & 0x1F) << (shift * 5);
        index++;
        shift++;
      } while (c >= 32);
      /* if value is negetive then bitwise not the value */
      if (result & 1 == 1) {
        result = ~result;
      }
      var result1 = (result >> 1) * 0.00001;
      lList.add(result1);
    } while (index < len);

/*adding to previous value as done in encoding */
    for (var i = 2; i < lList.length; i++) lList[i] += lList[i - 2];

    print(lList.toString());

    return lList;
  }

  // ! SEND REQUEST
  void sendRequest(String intendedLocation) async {

   if(intendedLocation != null){

    List<Placemark> placemark =
        await Geolocator().placemarkFromAddress(intendedLocation);
    double latitude = placemark[0].position.latitude;
    double longitude = placemark[0].position.longitude;
    LatLng destination = LatLng(latitude, longitude);
    _addMarker(destination, intendedLocation);
    String route = await _googleMapsServices.getRouteCoordinates(
        _initialPosition, destination);
    createRoute(route);
    notifyListeners(); }
  }

  // ! ON CAMERA MOVE
  void onCameraMove(CameraPosition position) {
    _lastPosition = position.target;
    notifyListeners();
  }

  // ! ON CREATE
  void onCreated(GoogleMapController controller) {
    _mapController = controller;
              mapController.setMapStyle('[ { "featureType": "all", "elementType": "labels.text.fill", "stylers": [ { "color": "#7c93a3" }, { "lightness": "-10" } ] }, { "featureType": "administrative.country", "elementType": "geometry", "stylers": [ { "visibility": "on" } ] }, { "featureType": "administrative.country", "elementType": "geometry.stroke", "stylers": [ { "color": "#a0a4a5" } ] }, { "featureType": "administrative.province", "elementType": "geometry.stroke", "stylers": [ { "color": "#62838e" } ] }, { "featureType": "landscape", "elementType": "geometry.fill", "stylers": [ { "color": "#dde3e3" } ] }, { "featureType": "landscape.man_made", "elementType": "geometry.stroke", "stylers": [ { "color": "#3f4a51" }, { "weight": "0.30" } ] }, { "featureType": "poi", "elementType": "all", "stylers": [ { "visibility": "simplified" } ] }, { "featureType": "poi.attraction", "elementType": "all", "stylers": [ { "visibility": "on" } ] }, { "featureType": "poi.business", "elementType": "all", "stylers": [ { "visibility": "off" } ] }, { "featureType": "poi.government", "elementType": "all", "stylers": [ { "visibility": "off" } ] }, { "featureType": "poi.park", "elementType": "all", "stylers": [ { "visibility": "on" } ] }, { "featureType": "poi.place_of_worship", "elementType": "all", "stylers": [ { "visibility": "off" } ] }, { "featureType": "poi.school", "elementType": "all", "stylers": [ { "visibility": "off" } ] }, { "featureType": "poi.sports_complex", "elementType": "all", "stylers": [ { "visibility": "off" } ] }, { "featureType": "road", "elementType": "all", "stylers": [ { "saturation": "-100" }, { "visibility": "on" } ] }, { "featureType": "road", "elementType": "geometry.stroke", "stylers": [ { "visibility": "on" } ] }, { "featureType": "road.highway", "elementType": "geometry.fill", "stylers": [ { "color": "#bbcacf" } ] }, { "featureType": "road.highway", "elementType": "geometry.stroke", "stylers": [ { "lightness": "0" }, { "color": "#bbcacf" }, { "weight": "0.50" } ] }, { "featureType": "road.highway", "elementType": "labels", "stylers": [ { "visibility": "on" } ] }, { "featureType": "road.highway", "elementType": "labels.text", "stylers": [ { "visibility": "on" } ] }, { "featureType": "road.highway.controlled_access", "elementType": "geometry.fill", "stylers": [ { "color": "#ffffff" } ] }, { "featureType": "road.highway.controlled_access", "elementType": "geometry.stroke", "stylers": [ { "color": "#a9b4b8" } ] }, { "featureType": "road.arterial", "elementType": "labels.icon", "stylers": [ { "invert_lightness": true }, { "saturation": "-7" }, { "lightness": "3" }, { "gamma": "1.80" }, { "weight": "0.01" } ] }, { "featureType": "transit", "elementType": "all", "stylers": [ { "visibility": "off" } ] }, { "featureType": "water", "elementType": "geometry.fill", "stylers": [ { "color": "#a3c7df" } ] } ]');

    notifyListeners();
  }


// FLOATING BUTTON TO LOCATION
 void toUserLocation(){

_mapController.animateCamera(
      CameraUpdate.newCameraPosition(
        CameraPosition(
            target: initialPosition, zoom: 15.0),
      ),
    );

      }

      void centerMap(String intendedLocation) async {


  List<Placemark> placemark =
        await Geolocator().placemarkFromAddress(intendedLocation);
    double latitude = placemark[0].position.latitude;
    double longitude = placemark[0].position.longitude;
    LatLng goToDestination = LatLng(latitude, longitude);   


_mapController.animateCamera(
      CameraUpdate.newLatLngBounds(
          LatLngBounds(
                southwest: LatLng(
                    _initialPosition.latitude <= goToDestination.latitude
                        ? _initialPosition.latitude
                        : goToDestination.latitude,
                    _initialPosition.longitude <= goToDestination.longitude
                        ? _initialPosition.longitude
                        : goToDestination.longitude),
                northeast: LatLng(
                    _initialPosition.latitude <= goToDestination.latitude
                        ? goToDestination.latitude
                        : _initialPosition.latitude,
                    _initialPosition.longitude <= goToDestination.longitude
                        ? goToDestination.longitude
                        : _initialPosition.longitude)),10.0),
    );

      }

void clearMap(){

_polyLines.clear();

_markers.clear();
 _mapController.animateCamera(
      CameraUpdate.newCameraPosition(
        CameraPosition(
            target: initialPosition, zoom: 15.0),
      ),
    );_mapController.animateCamera(
      CameraUpdate.newCameraPosition(
        CameraPosition(
            target: initialPosition, zoom: 15.0),
      ),
    );

}


//  LOADING INITIAL POSITION
  void _loadingInitialPosition()async{
    await Future.delayed(Duration(seconds: 5)).then((v) {
      if(_initialPosition == null){
        locationServiceActive = false;
        notifyListeners();
      }
    });
  }
}

here is my pubspec.yaml file

name: toladriver
description: A new Flutter project.

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  geolocator: 5.3.2+2
  provider: 4.1.3
  http: 0.12.1
  flutter_google_places: 0.2.5
  geocoder: 0.2.1
  fluttertoast : 4.0.1
  flutter_spinkit: "^2.1.0"
  slide_countdown_clock: 1.0.3

  google_maps_flutter: 0.5.28+1 
  google_maps_webservice: 0.0.17  

  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true      
  fonts:
    - family: Clan-Medium
      fonts:
        - asset: fonts/clan-book-webfont.ttf
        - asset: fonts/clan-med-webfont.ttf
          
like image 322
mac Avatar asked Jun 30 '20 05:06

mac


1 Answers

run the following commands on your project terminal:

1 - stopping the app

2 - flutter clean

3 - flutter pub get

4 - flutter run

like image 132
Mashood .h Avatar answered Jan 02 '23 11:01

Mashood .h