在模拟器上运行的应用程序运行完美,但是在真实设备上运行时,位置标记不可见,并且在运行代码时显示无法加载资产

如何解决在模拟器上运行的应用程序运行完美,但是在真实设备上运行时,位置标记不可见,并且在运行代码时显示无法加载资产

因为问题是在模拟器中一切正常,...即使在模拟器中成功加载资产,仍然显示堆栈无法加载资产,而且当我在真实设备上运行应用程序后在模拟器上成功测试应用程序后,位置标记不可见,在模拟器中可见

    //This is my code 

import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'components/map_pin_pill.dart';
import 'Model/pin_pill_info.dart';

const double CAMERA_ZOOM = 16;
const double CAMERA_TILT = 80;
const double CAMERA_BEARING = 30;
const LatLng SOURCE_LOCATION = LatLng(28.357932,77.167889);
const LatLng DEST_LOCATION = LatLng(28.354017,77.1605916);

void main() =>
    runApp(MaterialApp(debugShowCheckedModeBanner: false,home: MapPage()));

class MapPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MapPageState();
}

class MapPageState extends State<MapPage> {
  Completer<GoogleMapController> _controller = Completer();
  Set<Marker> _markers = Set<Marker>();
// for my drawn routes on the map
  Set<Polyline> _polylines = Set<Polyline>();
  List<LatLng> polylineCoordinates = [];
  PolylinePoints polylinePoints= PolylinePoints();
  String googleAPIKey = '';
// for my custom marker pins
  BitmapDescriptor sourceIcon;
  BitmapDescriptor destinationIcon;
// the user's initial location and current location
// as it moves
  LocationData currentLocation;
// a reference to the destination location
  LocationData destinationLocation;
// wrapper around the location API
  Location location;
  double pinPillPosition = -100;
  PinInformation currentlySelectedPin = PinInformation(
      pinPath: '',avatarPath: '',location: LatLng(0,0),locationName: '',labelColor: Colors.grey);
  PinInformation sourcePinInfo;
  PinInformation destinationPinInfo;

  @override
  void initState() {
    super.initState();

    // create an instance of Location
    location = new Location();
    polylinePoints = PolylinePoints();

    // subscribe to changes in the user's location
    // by "listening" to the location's onLocationChanged event
    location.onLocationChanged.listen((LocationData cLoc) {
      // cLoc contains the lat and long of the
      // current user's position in real time,// so we're holding on to it
      currentLocation = cLoc;
      updatePinOnMap();
    });
    // set custom marker pins
    setSourceAndDestinationIcons();
    // set the initial location
    setInitialLocation();
  }

  void setSourceAndDestinationIcons() async {
    BitmapDescriptor.fromAssetImage(
        ImageConfiguration(devicePixelRatio: 2.0),'assets/driving_pin.png')
        .then((onValue) {
      sourceIcon = onValue;
    });

    BitmapDescriptor.fromAssetImage(ImageConfiguration(devicePixelRatio: 2.0),'assets/destination_map_marker.png')
        .then((onValue) {
      destinationIcon = onValue;
    });
  }

  void setInitialLocation() async {
    // set the initial location by pulling the user's
    // current location from the location's getLocation()
    currentLocation = await location.getLocation();

    // hard-coded destination for this example
    destinationLocation = LocationData.fromMap({
      "latitude": DEST_LOCATION.latitude,"longitude": DEST_LOCATION.longitude
    });
  }

  @override
  Widget build(BuildContext context) {
    CameraPosition initialCameraPosition = CameraPosition(
        zoom: CAMERA_ZOOM,tilt: CAMERA_TILT,bearing: CAMERA_BEARING,target: SOURCE_LOCATION);
    if (currentLocation != null) {
      initialCameraPosition = CameraPosition(
          target: LatLng(currentLocation.latitude,currentLocation.longitude),zoom: CAMERA_ZOOM,bearing: CAMERA_BEARING);
    }
    return Scaffold(
      body: Stack(
        children: <Widget>[
          GoogleMap(
              myLocationEnabled: true,compassEnabled: true,tiltGesturesEnabled: false,markers: _markers,polylines: _polylines,mapType: MapType.normal,initialCameraPosition: initialCameraPosition,onTap: (LatLng loc) {
                pinPillPosition = -100;
              },onMapCreated: (GoogleMapController controller) {//dikkat
               // controller.setMapStyle(Utils.mapStyles);
                _controller.complete(controller);
                // my map has completed being created;
                // i'm ready to show the pins on the map
                showPinsOnMap();
              }),MapPinPillComponent(
              pinPillPosition: pinPillPosition,currentlySelectedPin: currentlySelectedPin),Positioned(
              bottom: 90,right: 10,child:
              FlatButton(
                  child: Icon(Icons.pin_drop,color: Colors.white),color: Colors.green,onPressed: updatePinOnMap
              )
          ),],),);
  }

  void showPinsOnMap() {
    // get a LatLng for the source location
    // from the LocationData currentLocation object
    var pinPosition =
    LatLng(currentLocation.latitude,currentLocation.longitude);
    // get a LatLng out of the LocationData object
    var destPosition =
    LatLng(destinationLocation.latitude,destinationLocation.longitude);

    sourcePinInfo = PinInformation(
        locationName: "Start Location",location: SOURCE_LOCATION,pinPath: "assets/driving_pin.png",avatarPath: "assets/friend1.jpg",labelColor: Colors.blueAccent);

    destinationPinInfo = PinInformation(
        locationName: "End Location",location: DEST_LOCATION,pinPath: "assets/destination_map_marker.png",avatarPath: "assets/friend2.jpg",labelColor: Colors.purple);

    // add the initial source location pin
    _markers.add(Marker(
        markerId: MarkerId('sourcePin'),position: pinPosition,onTap: () {
          setState(() {
            currentlySelectedPin = sourcePinInfo;
            pinPillPosition = 0;
          });
        },icon: sourceIcon));
    // destination pin
    _markers.add(Marker(
        markerId: MarkerId('destPin'),position: destPosition,onTap: () {
          setState(() {
            currentlySelectedPin = destinationPinInfo;
            pinPillPosition = 0;
          });
        },icon: destinationIcon));
    // set the route lines on the map from source to destination
    // for more info follow this tutorial
    setPolylines();
  }

  void setPolylines() async {
    PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(googleAPIKey,PointLatLng(currentLocation.latitude,PointLatLng(destinationLocation.latitude,destinationLocation.longitude));

    if(result.points.isNotEmpty) {
      print("not empty");
      result.points.forEach((PointLatLng point) {
        polylineCoordinates.add(LatLng(point.latitude,point.longitude));
      });

      setState(() {
        _polylines.add(Polyline(
            width: 3,// set the width of the polylines
            polylineId: PolylineId("poly"),color: Color.fromARGB(255,40,122,198),points: polylineCoordinates));
      });
    }
  }

  void updatePinOnMap() async {
    // create a new CameraPosition instance
    // every time the location changes,so the camera
    // follows the pin as it moves with an animation
    CameraPosition cPosition = CameraPosition(
      zoom: CAMERA_ZOOM,target: LatLng(currentLocation.latitude,);
    final GoogleMapController controller = await _controller.future;
    controller.animateCamera(CameraUpdate.newCameraPosition(cPosition));
    // do this inside the setState() so Flutter gets notified
    // that a widget update is due
    setState(() {
      // updated position
      var pinPosition =
      LatLng(currentLocation.latitude,currentLocation.longitude);

      sourcePinInfo.location = pinPosition;

      // the trick is to remove the marker (by id)
      // and add it again at the updated location
      _markers.removeWhere((m) => m.markerId.value == 'sourcePin');
      _markers.add(Marker(
          markerId: MarkerId('sourcePin'),onTap: () {
            setState(() {
              currentlySelectedPin = sourcePinInfo;
              pinPillPosition = 0;
            });
          },// updated position
          icon: sourceIcon));
    });
  }
}
 

//和即将到来的堆栈在下面

Syncing files to device Android SDK built for x86...
D/EGL_emulation( 9741): eglMakeCurrent: 0xa6584ea0: ver 2 0 (tinfo 0x90713ec0)
E/BufferQueueProducer( 9741): [SurfaceTexture-0-9741-1] setAsyncMode: BufferQueue has been abandoned
E/BufferQueueProducer( 9741): [SurfaceTexture-0-9741-1] cancelBuffer: BufferQueue has been abandoned
Restarted application in 3,158ms.
W/DynamiteModule( 9741): Local module descriptor class for providerinstaller not found.
I/DynamiteModule( 9741): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller( 9741): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/ConnectivityManager.CallbackHandler( 9741): callback not found for CALLBACK_CAP_CHANGED message
W/ConnectivityManager.CallbackHandler( 9741): callback not found for CALLBACK_IP_CHANGED message
W/DynamiteModule( 9741): Local module descriptor class for providerinstaller not found.
I/DynamiteModule( 9741): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller( 9741): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/ConnectivityManager.CallbackHandler( 9741): callback not found for CALLBACK_IP_CHANGED message
I/Google Maps Android API( 9741): Google Play services package version: 203019022
D/        ( 9741): HostConnection::get() New Host Connection established 0x872a9500,tid 10180
D/EGL_emulation( 9741): eglCreateContext: 0x8f55fda0: maj 1 min 0 rcv 1
D/EGL_emulation( 9741): eglMakeCurrent: 0xa6584ea0: ver 2 0 (tinfo 0x90713ec0)
I/flutter ( 9741): GOOGLE MAPS URL: https://maps.googleapis.com/maps/api/directions/json?origin=28.3524217%2C77.3368383&destination=28.354017%2C77.16059159999998&mode=driving&avoidHighways=false&avoidFerries=true&avoidTolls=false&key=API_KEY
D/EGL_emulation( 9741): eglMakeCurrent: 0x8f55fda0: ver 1 0 (tinfo 0x8f4360f0)

══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset:

When the exception was thrown,this was the stack:
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:223:7)
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:669:31)
#2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:652:14)
#3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:505:13)
#4      ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:360:22)
#5      ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:503:80)
#6      ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:108:19)
#7      ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:334:9)
#8      ImageProvider._createErrorHandlerAndKey.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:464:26)
(elided 13 frames from dart:async)

Image provider: AssetImage(bundle: null,name: "")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#b540c(),name: "",scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by image resource service ════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: 

When the exception was thrown,this was the stack: 
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:223:7)
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:669:31)
#2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:652:14)
#3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:505:13)
...
Image provider: AssetImage(bundle: null,scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
I/zygote  ( 9741): NativeAlloc concurrent copying GC freed 49007(2MB) AllocSpace objects,12(720KB) LOS objects,40% free,8MB/14MB,paused 587us total 174.752ms
I/zygote  ( 9741): NativeAlloc concurrent copying GC freed 18774(778KB) AllocSpace objects,0(0B) LOS objects,42% free,paused 1.075ms total 187.684ms
I/zygote  ( 9741): NativeAlloc concurrent copying GC freed 4679(318KB) AllocSpace objects,paused 22.482ms total 146.268ms
D/        ( 9741): HostConnection::get() New Host Connection established 0xa3bc5200,tid 9963
D/        ( 9741): HostConnection::get() New Host Connection established 0xa3bc5d40,tid 10271
D/        ( 9741): HostConnection::get() New Host Connection established 0x77dfe380,tid 10294

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-