当前位置:网站首页>Flutter development: error The following assertion was thrown resolving an image codec: Solution for Unable to...
Flutter development: error The following assertion was thrown resolving an image codec: Solution for Unable to...
2022-08-10 05:04:00 【Three shopkeepers 666】
Foreword
In the development of Flutter, we often encounter some strange errors, such as errors after version updates, errors if files are not imported, errors of inconsistent versions of third-party plug-ins, etc., and in recent years, Flutter has continued to improve andThe speed of updates is getting faster and faster, which requires Flutter-related developers to keep a continuous learning attitude to deal with various emergencies encountered in Flutter development.This blog post will share about the solution to the error The following assertion was thrown resolving an image codec: Unable to load asset: ... after running the Flutter project in Flutter development, record it for later reference.
Error message
After running the flutter run command in the terminal, the project console reports an error. The specific error message is as follows:
===| Exception caught by image resource service |================
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/mine/mine_set.png
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:224:7)
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:675:14)
Image provider: AssetImage(bundle: null, name: "assets/mine/mine_set.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dd41f(), name: "assets/mine/mine_set.png", scale: 1.0)
==========================================================
Another exception was thrown: Unable to load asset: assets/mine/mine_arr01.png

Analysis
Although the error reported by the terminal is so long, the key sentence is "The following assertion was thrown resolving an image codec: Unable to load asset: assets/mine/mine_set.png", because when the resource file was created, the configuration image path is not introduced in Flutter's pubspec.yaml file, otherwise it will report an error that the image resource cannot be found after running.

Solution
1. After the newly created folder mine for storing pictures in the project root directory, you need to introduce the path for storing pictures
2. Then open the pubspec.yaml file under the project root directory, and then add assets/mine to assets. The specific operations are as follows:
flutter:# The following line ensures that the Material Icons font is# included with your application, so that you can use the icons in# the material Icons class.uses-material-design: true# To add assets to your application, add an assets section, like this:assets: - assets/mine/

3. Finally, when using image resources, it is also loaded using relative paths, and the image data can be loaded through the Image component.
4. Re-run the project, no error is reported, so the problem is solved perfectly.
Note: assets: is an option under flutter, so the space reserved in front of assets: must be aligned with other options in flutter, this is the standard format, and the image will be loaded and displayed normally.
Last
The following assertion was thrown resolving an image codec: Unable to load asset: ... in the development of Flutter introduced above, after running the Flutter project, the following assertion was thrown resolving an image codec: Unable to load asset: ... The solution steps, if you encounter similar problems caused by the introduction method in the futureIt's easy to solve, especially for developers who are new to Flutter development, they should master the solution to this situation, and I won't go into details here.
The above is the whole content of this chapter. Welcome to pay attention to the WeChat public account of the three shopkeepers "Program Ape by the three shopkeepers", and the Sina Weibo of the three shopkeepers "Three shopkeepers 666", welcome to pay attention!
边栏推荐
- 咨询cdc 2.0 for mysql不执行flush with read lock.怎么保证bin
- 大佬们,mysql cdc(2.2.1跟之前的版本)从savepoint起有时出现这种情况,有没有什
- Big guys, mysql cdc (2.2.1 and previous versions) sometimes has this situation since savepoint, is there anything wrong?
- 众昂矿业:萤石下游需求强劲
- Guys, is it normal that the oracle archive log grows by 3G in 20 minutes after running cdc?
- LeetCode·124.二叉树中的最大路径和·递归
- pytorch 学习
- 【LeetCode】41、 缺失的第一个正数
- Shell编程三剑客之awk
- Mysql CDC (2.1.1) inital snapshot database set up five concurrent degree, se
猜你喜欢
随机推荐
【LeetCode】41、 缺失的第一个正数
FPGA工程师面试试题集锦11~20
如何在不同场景下选择合适的示波器探头
【LeetCode】Day111-字母异位词分组
mysql cdc (2.1.1)inital snapshot数据库的时候设置了5个并发度,se
【心理学·人物】第二期(学术X综艺)
解决“#231-D declaration is not visible outside of function”告警方法
元宇宙 | 你能通过图灵测试吗?
JS gets the year, month, day, time, etc. of the current time
Guys, the test in the idea uses FlinkCDC SQL to read Mysql data and write it into Kafka. The code creates
线性代数(四)
2022 security officer C certificate test and simulation test in shandong province
顺序表的删除,插入和查找操作
线性模型中的高级特征选择技术——基于R
openvino 安装(01)
pytorch 学习
EasyGBS连接mysql数据库提示“can’t connect to mysql server”,该如何解决?
22牛客多校3 A.Ancestor(LCA + 枚举)
JS获取当前时间的年、月、日、时间等
WAN技术-1广域网接口









