flutter - 使用 Image.file 构造函数创建对象时出错
问题描述
我正在尝试使用 Image.file () 创建带有图像的小部件,但在尝试时发生错误
代码:
import 'package:flutter/material.dart';
import 'dart:io';
void main() {
runApp(StateApp());
}
class StateApp extends StatefulWidget {
State<StatefulWidget> createState() {
return Application();
}
}
class Application extends State<StateApp> {
Widget build(BuildContext con) {
return MaterialApp(
home:Scaffold(
appBar: AppBar(
title: Text('Title'),
),
body: Image.file(File("/home/suchin/1.png")),
),
);
}
}
错误日志:
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following UnsupportedError was thrown resolving an image codec:
Unsupported operation: _Namespace
When the exception was thrown, this was the stack:
...
Path: /home/user/1.png
════════════════════════════════════════════════════════════════════════════════════════════════════
这是什么原因?
解决方案
你从哪里得到路径?看起来不像移动路径
试试这个包来挑选图像,然后你可以显示结果
推荐阅读
- r - 如何从 R 中的 mlr 包创建的模型中删除变量?
- python - 如何使用 pip3 查看软件包的哪些版本(平台/版本/abi)可用?
- python - entry_point 脚本存储在自定义 Sagemaker Framework 培训作业容器中的什么位置?
- flutter - 当 Flutter 中的全局变量更改(异步)时更新小部件
- c++ - 程序在 c++ 中终止;
- reactjs - 未应用反应样式对象
- python - 将来自 http 请求的 json 响应过滤为仅特定值,然后从所有结果中选择最大的“id”值
- xamarin - Xamarin - ITMS-90683:Info.plist 中缺少目的字符串
- android - 如果键盘可见,Android 布局会被压缩
- scripting - 将文件作为邮件正文发送时的 Bash 脚本格式问题