RangeError:抖动图像压缩问题

时间:2020-10-16 19:39:44

标签: android ios flutter compression flutter-dependencies

我正在使用Flutter插件flutter_image_compress

下面是代码

RangeError: Value not in range: -1

这将返回以下错误

// Default to null
val color1: Color? = Color.values().getOrNull(bOrdinal)

// Default to a value
val color2: Color = Color.values().getOrElse(bOrdinal) { Color.RED }

为什么会这样?

1 个答案:

答案 0 :(得分:0)

我认为问题与字符串有关。您需要确保文件名以.jpg或.jpeg结尾,而不是以.png或类似的名称结尾。

final filePath = file.absolute.path;

// Create output file path
// eg:- "Volume/VM/abcd_out.jpeg"
final lastIndex = filePath.lastIndexOf(new RegExp(r'.jp'));
final splitted = filePath.substring(0, (lastIndex));
final outPath = "${splitted}_out${filePath.substring(lastIndex)}";