我想使用我添加到代码中的占位符图像文件作为"assets/placeholder.png"
,但是我收到一个找不到文件的错误.这就是我在Dartlang文档中的做法.
var bytes = await new File('assets/placeholder.png').readAsBytes();
String base64 = CryptoUtils.bytesToBase64(bytes);
每一次都有bytes
个变量错误.如何保存本地保存的图像文件的字节?
我想使用我添加到代码中的占位符图像文件作为"assets/placeholder.png"
,但是我收到一个找不到文件的错误.这就是我在Dartlang文档中的做法.
var bytes = await new File('assets/placeholder.png').readAsBytes();
String base64 = CryptoUtils.bytesToBase64(bytes);
每一次都有bytes
个变量错误.如何保存本地保存的图像文件的字节?
使用Flutter 环境时,如果要访问资源(https://flutter.io/assets-and-images/),则必须使用AssetBundle
.
import 'package:flutter/services.dart' show rootBundle;
ByteData bytes = await rootBundle.load('assets/placeholder.png');