相关疑难解决方法(0)

如何将资产图像转换为文件?

有没有办法将资产图像用作文件。我需要一个文件,以便它可以用于使用 http 在 Internet 上进行测试。我已经尝试了 Stackoverflow.com 的一些答案(如何使用 image.file 加载图像)但收到错误“无法打开文件,(操作系统错误:没有这样的文件或目录,errno = 2)”。附加的代码行也给出了错误。

File f = File('images/myImage.jpg');

RaisedButton(
   onPressed: ()=> showDialog(
     context: context,
     builder: (_) => Container(child: Image.file(f),)),
   child: Text('Show Image'),)
Run Code Online (Sandbox Code Playgroud)

使用 Image.memory 小部件(有效)

Future<Null> myGetByte() async {
    _byteData = await rootBundle.load('images/myImage.jpg');
  }

  /// called inside build function
  Future<File> fileByte = myGetByte();

 /// Show Image
 Container(child: fileByte != null
 ? Image.memory(_byteData.buffer.asUint8List(_byteData.offsetInBytes, _ 
 byteData.lengthInBytes))
 : Text('No Image File'))),
Run Code Online (Sandbox Code Playgroud)

dart flutter

25
推荐指数
1
解决办法
3万
查看次数

标签 统计

dart ×1

flutter ×1