当前位置: 首页 > 知识库问答 >
问题:

缺少插图异常 (缺少插图例外(未找到方法相机的实现#在通道 plugins.flutter.io/google_maps_53)上动画)

皇甫才良
2023-03-14

我最近在我的颤动应用程序中安装了谷歌地图,但我一直得到这个错误,

缺少插图异常 (缺少插图例外(未找到方法相机的实现#在通道 plugins.flutter.io/google_maps_53)上动画)

这发生在我调用的每个地图控制器上,即使是oncreate方法也给我带来了同样的问题,我第一次尝试了颤振清理和颤振酒吧获取,但没有用,现在我不知道了。

这是我创建地图的主dart文件

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,   
),

这是我单独的应用程序。

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();
      }
    });
  }
}

这是我的pubspec。yaml文件

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
          

共有3个答案

仰翔
2023-03-14

确认您的Google地图API密钥是否有效。验证密钥时会抛出该错误。

孔永年
2023-03-14

您需要添加以下依赖项:

dependencies:
  google_maps_flutter: ^0.5.28+1

https://pub . dev/packages/Google _ maps _ flutter #-安装-tab-

乌甫
2023-03-14

在项目终端上运行以下命令:

1 - 停止应用

2-颤振清洁

3-颤振酒吧获取

4-颤振运行

 类似资料:
  • 使用Flatter的google登录 但是当我使用此语句登录用户时看到以下消息 E/flutter(6491): MisSingPluginExcture(在通道plugins.flutter.io/google_sign_in上没有找到方法初始化的实现) 我验证了以下步骤: 用户是否经常报告此错误。不确定如何继续。我在做大多数医生说的事情,但它不起作用。 我看到的另一个奇怪的行为是,我第一次运行

  • 我之前问过类似的问题,但是在将我的应用发布到 Play 商店的内部和封闭测试后,我在 Google 登录时遇到问题。它在Android和iOS的模拟器上运行良好,当我以调试和发布模式从计算机运行它时,它在真实设备上运行效果很好,但是一旦发布到Play商店,一切都会中断。我得到的错误是 MissingPluginException(在通道plugins.flutter.io/google_sign_

  • 我曾尝试用Flutter实现Firebase云消息传递,直到我使用“本地通知”插件来显示通知,我才获得成功 我的通知在前台工作正常,但在后台显示此错误: [错误:flatter/lib/ui/ui_dart_state.cc(157)]未处理的异常:缺少PluginException(在channel dexterous.com/flatter/local_通知上未找到方法显示的实现) 我使用Fi

  • 对于和的未处理插件异常,我收到一个错误: 未处理的异常:MissingPluginException(在channel plugins.flatter.io/shared_首选项上找不到方法getAll的实现)未处理的异常:MissingPluginException(在channel plugins.flatter.io/path_provider上找不到方法getApplicationSupp

  • 我是groovy的新手。我有这样的代码。 串味 从这个客户端映射中,我需要迭代appName和enable的值。为此,我使用了get方法。。。我对此不确定。 使用此get方法时,我遇到以下错误。因为我是groovy新手,所以我不知道这里发生了什么 棒极了。lang.MissingMethodException:没有方法com的签名。康卡斯特。csv。哈克索。SecureFirebaseRestCl

  • MissingPluginException(在plugins.flutter.io/url_launcher通道上找不到方法canLaunch的实现) MissingPluginException(在plugins.flutter.io/share通道上找不到方法canLaunch的实现) MissingPluginException(在通道plugins.flutter.io/google_m