【发布时间】:2020-05-23 11:43:05
【问题描述】:
在 Flutter 中在 Google Map 中创建自定义图标显示错误。
我的 pubspec.yaml 文件
assets:
- assets/truck.png
我的代码是:
void getCustomIcon() async {
customIcon = await BitmapDescriptor.fromAssetImage(
ImageConfiguration(
devicePixelRatio: 2.5,
),
'assets/truck.png');
}
错误是:
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Failed to decode image. The provided image must be a Bitmap., null)
E/flutter (15757): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (15757): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
【问题讨论】:
-
您是否为资产配置了 pubspec。我认为您缺少配置
-
@Dev 我在 assets 文件夹中添加了该图像,并在 pubspec 文件中也提到了兄弟。
-
创建标记的代码是什么
-
@Dev 我在我的问题中添加了用于创建标记的代码,并在我的类的 initstate 中调用了该方法
标签: google-maps flutter dart maps google-maps-markers