Flutter Web How to Convert Uint8List to File

3,062

Since dart:io isn't avalible on web, you can use the universal_io package.

Add it to your pubspec.yaml.

import 'package:universal_io/io.dart';

File createFileFromBytes(Uint8List bytes) => File.fromRawPath(bytes);
Share:
3,062
Jolzal
Author by

Jolzal

Updated on December 29, 2022

Comments

  • Jolzal
    Jolzal about 1 year

    I am having trouble on converting Uint8List image to File on flutter web since dart:io is not supported on the web, i need it to be file in order to upload it to FirebaseStorage, is there any workaround for this ? thankyou

  • Jolzal
    Jolzal almost 3 years
    isnt dart : io not supported on flutter-web?
  • Andrej
    Andrej almost 3 years
    Yes, you are right. dart:io isn't avalibe on web, but you can use the universal_io package.
  • Jolzal
    Jolzal almost 3 years
    ah thankyou i dont know that package exist, will accept your answer after i tried it
  • Andrej
    Andrej almost 3 years
    Okay, here is the package on pub: pub.dev/packages/universal_io
  • Jeff Frazier
    Jeff Frazier about 2 years
    For me, this returns Error: FormatException: Unexpected extension byte (at offset 0). There are several similar issues reported and the author has yet to reply to any of them.
  • PixelToast
    PixelToast almost 2 years
    This is not the answer, this uses the Uint8List as the file path, not the actual contents