【发布时间】:2021-01-18 16:02:03
【问题描述】:
我在pub.dev 上使用多文件选择器包,链接在https://pub.dev/packages/multi_image_picker 下方以及Yalantis 的图像裁剪器包
https://pub.dev/packages/image_cropper
让我的用户选择多张图像,然后随意裁剪它们。
我正在使用此代码将我的资产转换为文件并将其提供给裁剪器。它有效。
final temp = await Directory.systemTemp.createTemp();
final data = await finalList[index].getByteData();
File failo = await File('${temp.path}/img').writeAsBytes(
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
print("The path is ${temp.path}");
File croppedFailo = await ImageCropper.cropImage(
sourcePath: failo.path,
androidUiSettings: AndroidUiSettings(toolbarTitle: "My App"),
);
棘手的一点是将它转换回资产,以便我可以用这个新裁剪的资产替换旧的 uncropped 资产。我通读了包的资产文档并尝试了这个,但它使我的应用程序崩溃
Asset croppedPic = new Asset(
croppedFailo.path,
DateTime.now().millisecondsSinceEpoch.toString(),
300,
300,
);
finalList.replaceRange(index, index + 1, [croppedPic]);
编辑:当我说“资产”时,我指的不是我手动添加到应用程序的资产/图像文件夹中的图像。多图像选择器插件有一个称为资产的文件类型,它在其中返回图像。这就是我要将文件转换回的类型。
【问题讨论】:
-
“棘手的一点是将其转换回资产” - 抱歉,资产是只读的
标签: flutter flutter-packages cropper flutter-file