Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在flatter中使用Image.file小部件 “” I/Flatter(7954):解析图像编解码器时引发以下FileSystemException: I/flatter(7954):无法打开文件,路径='image.png'(操作系统错误:没有这样的文件或目录,errno=2) I/颤振(7954): I/flatter(7954):抛出异常时,这是堆栈: I/flatter(7954):#0 _File.open。(dart:io/file_impl.dart:366:9) I/颤振(7954):(从dart中删除13帧:异步) I/颤振(7954):。。。 I/颤振(7954): I/flatter(7954):路径:image.png I/颤振(7954):════════════════════════════════════════════════════════════════════════════════════════════════════_Flutter - Fatal编程技术网

Flutter 如何在flatter中使用Image.file小部件 “” I/Flatter(7954):解析图像编解码器时引发以下FileSystemException: I/flatter(7954):无法打开文件,路径='image.png'(操作系统错误:没有这样的文件或目录,errno=2) I/颤振(7954): I/flatter(7954):抛出异常时,这是堆栈: I/flatter(7954):#0 _File.open。(dart:io/file_impl.dart:366:9) I/颤振(7954):(从dart中删除13帧:异步) I/颤振(7954):。。。 I/颤振(7954): I/flatter(7954):路径:image.png I/颤振(7954):════════════════════════════════════════════════════════════════════════════════════════════════════

Flutter 如何在flatter中使用Image.file小部件 “” I/Flatter(7954):解析图像编解码器时引发以下FileSystemException: I/flatter(7954):无法打开文件,路径='image.png'(操作系统错误:没有这样的文件或目录,errno=2) I/颤振(7954): I/flatter(7954):抛出异常时,这是堆栈: I/flatter(7954):#0 _File.open。(dart:io/file_impl.dart:366:9) I/颤振(7954):(从dart中删除13帧:异步) I/颤振(7954):。。。 I/颤振(7954): I/flatter(7954):路径:image.png I/颤振(7954):════════════════════════════════════════════════════════════════════════════════════════════════════,flutter,Flutter,我正在使用image.file显示小部件,但它引发了以下异常如何解决此问题,我将代码添加为image。image.asset小部件和image.file小部件之间的主要区别是什么。请提前感谢。您需要添加文件的正确位置: ''' I/flutter ( 7954): The following FileSystemException was thrown resolving an image codec: I/flutter ( 7954): Cannot open file, path = 'i


我正在使用image.file显示小部件,但它引发了以下异常如何解决此问题,我将代码添加为image。image.asset小部件和image.file小部件之间的主要区别是什么。请提前感谢。

您需要添加文件的正确位置:

'''
I/flutter ( 7954): The following FileSystemException was thrown resolving an image codec:
I/flutter ( 7954): Cannot open file, path = 'image.png' (OS Error: No such file or directory, errno = 2)
I/flutter ( 7954): 
I/flutter ( 7954): When the exception was thrown, this was the stack:
I/flutter ( 7954): #0      _File.open.<anonymous closure> (dart:io/file_impl.dart:366:9)
I/flutter ( 7954): (elided 13 frames from dart:async)
I/flutter ( 7954): ...
I/flutter ( 7954): 
I/flutter ( 7954): Path: image.png
I/flutter ( 7954): ════════════════════════════════════════════════════════════════════════════════════════════════════
加载图像的另一种方法是将图像添加到项目中的
assets
文件夹中,然后在
pubspec.yaml
中,可以执行以下操作:

File file = new File('directoryLocation/image.png');
然后做:

flutter:
  assets:
    - assets/my_icon.png
    - assets/background.png
检查文档:


Image.asset
用于从项目
assets
文件夹加载图像。因为它已经在项目中可用,并且使用的前言非常直接

Widget build(BuildContext context) {
  return Image(image: AssetImage('assets/my_icon.png'));
}
另一方面,
Image.file
用于从设备内部/外部存储器加载图像。这样,您必须使用ImagePicker或任何其他库来定位图像,以获取图像的路径。使用此
路径
创建文件对象并将其提供给
Image.File

Image.asset('assets/image.jpg');

在image.file中,我给出了文件的目录位置,但它引发了如下异常:无法打开文件,path='/document/raw:/storage/emulated/0/Download//\u image.png'(操作系统错误:没有这样的文件或目录,errno=2),您从哪里获取文件?如果您是从设备中的图库获取文件,那么只需使用image_picker插件我是从下载文件夹获取文件。如果是图像,则使用我在上面链接的插件好的,我尝试该插件
String path = 'your/image/path/here';
File imageFile = File(path);
Widget image = Image.file(imageFile);