【发布时间】:2022-01-25 15:25:37
【问题描述】:
我正在尝试使用 flutter image compress package 压缩图像
Future<File> testCompressAndGetFile(File file) async {
final lastIndex = file.absolute.path.lastIndexOf(new RegExp(r'.jp')); //this returns -1
final splitted = file.absolute.path.substring(0, (lastIndex)); // I always get the error from here
String oP = "${splitted}_ql${file.absolute.path.substring(lastIndex)}";
final result = await FlutterImageCompress.compressAndGetFile(
file.absolute.path,
oP,
quality: 95,
);
return result;
}
当我打印 lastIndex 时,我得到的 -1 不在 0-70 的范围内。
并因此 splitted 引发错误
RangeError (end): Invalid value: Not in inclusive range 0..70: -1
请问我该如何解决这个错误
【问题讨论】:
-
问题主要出在您的文件与正则表达式相结合。您尝试使用此函数压缩的文件及其路径是什么?