I've been struggling with this error for past few days, and I can't seem to find any useful answers online, so any help would be much appreciated!
I'm working with Flutter Web, and I am using universal_io package due to dart:io not being supported on the web. With help of an Image package I am converting file from Jpg to Png and am trying to convert recieved Unit8List
of an converted file to an File
variable. However that doesn't seem to work.
I KEEP GETTING THIS ERROR:
Error: FormatException: Unexpected extension byte (at offset 0)
WHAT I'M DOING:
I am trying to convert an Unit8List to an File Variable with this line:
File convertedFile = File.fromRawPath(png);
with png
being an Unit8List.
FULL CODE:
convertFiles() async {
//1. Requesting file from the internet [✓ works]
http.Response response = await http.get(
Uri.parse(folderFiles[openFileIndex.value]["link"]),
);
//2. Decoding WEBP image with "Image" package [✓ works]
var image = img.decodeWebP(response.bodyBytes);
//3. Encoding decoded WEBP file as an PNG [✓ works]
Uint8List png = img.encodePng(image!) as Uint8List;
//4. Trying to convert file bytes(Unit8List) to a File Variable [✗ throws an error]
File convertedFile = File.fromRawPath(png);
}
VSCode Screenshot
WHAT I TRIED:
I've tried everything I've seen on the internet including moving to Master
channel and Upgrading Flutter, but none of those things solved the problem.
FLUTTER DOCTOR:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 3.5.0-4.0.pre.23, on macOS 12.6 21G115 darwin-arm64, locale en-SI)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.71.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
• No issues found!
Terminal Screenshot