【发布时间】:2021-10-13 15:23:21
【问题描述】:
所以我想将我的图像存储到列表中,但我无法将其转换为 Uint8list 有没有办法在颤振中使用其他选项,例如 RootBundle ???
为什么不使用 RootBundler ?? 问题是 RootBundle 需要在 Asset 部分下的 Pubspec.yaml 上声明 但是我要转换的图像位于 App 临时目录中,我无法更改 所以 RootBundle 无法访问并且总是抛出 Asset is null (不是),因为它没有在 pubspec.yaml 中声明
static Future pickImage(PickType type) async {
try {
var photo = await ImagePicker().pickImage(
source:
type == PickType.Camera ? ImageSource.camera : ImageSource.gallery,
imageQuality: 80,
);
var photosPicked;
print(photo!.name);
Directory tempDir = await getTemporaryDirectory();
print(tempDir.path);
rootBundle
.load('${tempDir.path}/${photo.name}')
.then((value) => photosPicked = value);
return photosPicked;
} catch (e) {
print(e);
}
}
【问题讨论】:
-
不,rootBundle 只能访问本地资产