flutter - Flutter 无法正确加载所有 SVG
问题描述
我的一些 SVG 资产有问题,它们没有正确加载:
flutter:未处理的元素模式;图片键:AssetBundlePictureKey(bundle: PlatformAssetBundle#bc01d(), name: "assets/images/list_images/avocado.svg", colorFilter: null)
颤振:引发了另一个异常:无法找到 url 的定义(#pattern0)
这些是我的paths
:
`class ListImagePath {
static const avocado = "assets/images/list_images/avocado.svg";
static const balloon = "assets/images/list_images/balloon.svg";
static const beer = "assets/images/list_images/beer.svg";
static const bike = "assets/images/list_images/bike.svg";
static const book = "assets/images/list_images/book.svg";
static const christmas = "assets/images/list_images/christmas.svg";
static const dress = "assets/images/list_images/dress.svg";
static const egg = "assets/images/list_images/egg.svg";
static const furniture = "assets/images/list_images/furniture.svg";
static const gift_1 = "assets/images/list_images/gift_1.svg";
static const gift_2 = "assets/images/list_images/gift_2.svg";
static const goals = "assets/images/list_images/goals.svg";
static const main = "assets/images/list_images/main.svg";
static const roller = "assets/images/list_images/roller.svg";
static const shirt = "assets/images/list_images/shirt.svg";
static const shoe = "assets/images/list_images/shoe.svg";
static const technik = "assets/images/list_images/technik.svg";
static const travel = "assets/images/list_images/travel.svg";
static const wine = "assets/images/list_images/wine.svg";
static const defaultImagePath = "assets/images/list_images/default.svg";
}`
我的pubspec
:
flutter:
uses-material-design: true
assets:
- assets/images/background_images/
- assets/images/list_images/
我在这里想念什么?这是常见的 Flutter_SVG 错误吗?我怎样才能解决这个问题?
如果您需要更多信息,请告诉我。
解决方案
我正在使用 Flutter Web,最近不得不降级:
flutter channel beta
flutter downgrade 1.25.0-8.3.pre
因为 1.26.0-17.3.pre 似乎在 SVG 方面被破坏了:像 Image.network("assets/cube.svg") 这样的代码会导致
======== Exception caught by image resource service ================================================
The following ImageCodecException was thrown resolving an image codec:
Failed to decode image data.
Image source: http://localhost:45923/assets/cube.svg
When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49 throw_
lib/_engine/engine/canvaskit/image.dart 102:7 createDefault
lib/_engine/engine/canvaskit/skia_object_cache.dart 141:41 new
lib/_engine/engine/canvaskit/image.dart 92:3 decodeFromBytes
lib/_engine/engine/canvaskit/image.dart 75:53 <fn>
...
Image provider: NetworkImage("assets/cube.svg", scale: 1)
Image key: NetworkImage("assets/cube.svg", scale: 1)
不知道最新版本有没有修复
推荐阅读
- sql - 合并两个表但删除某个列中的重复项
- python - 我们可以同时执行两个矩阵的外积吗?
- php - Wordpress 过滤器 - 获取用户名
- swift - Amplify Schema 抱怨,因为参数类型不是“列表”
? - revit-api - Revit插件模板2020
- javascript - 如何根据反应状态向数组添加复选框值?
- sql - 当其中的所有值都是 VarChar 值时,DECODE 如何知道要评估什么?
- java - Mongotemplate 更新更改文档结构
- python - 通过 USB 将存储从 android 复制到 PC 以从 android 恢复已删除的照片
- dataframe - 在大数据上将 group_by 系列连接成一个