0

i have tried multiple solutions but stuck to solve how do i get full image bytes which is only possible by readStream.listen but unable to solve.

    Future<Uint8List> pickImage()async {
  List<int> bytes = [];
 var result = await FilePicker.platform.pickFiles(
    dialogTitle: "Please Choose Image File",
    withReadStream: true,
    type: FileType.custom,
    allowedExtensions: ["jpg", "png", "jpeg", "gif", "bmp"],
  );


  return Uint8List.fromList(await result!.files.first.readStream!.first);
}

This is first try to get bytes without getting percentage received chunks but got null after a sec.

    Future<Uint8List> pickImage()async {
  List<int> bytes = [];
  FilePicker.platform.pickFiles(
    dialogTitle: "Please Choose Image File",
    withReadStream: true,
    type: FileType.custom,
    allowedExtensions: ["jpg", "png", "jpeg", "gif", "bmp"],
  ).then((result) {
    if (result != null) {
      result.files.first.readStream!.listen((event) {
        bytes.addAll(event);
        print((Uint8List
            .fromList(bytes)
            .lengthInBytes /
            result.files.first.size) *
            100);
      });
      print(result.files.first.name);
      print(result.files.first.size);
    }
  });

  return Uint8List.fromList(bytes);
}

This is 2nd try to get bytes with %age received which i actually need but this cannot wait for listening all chunks of bytes and return the object

call of function

controller.cropImageWeb(await pickImage(),);

i also tried to use ImagePicker() which is working 100% on web but the issue is i cannot get the name of file size before reading file and %age of completion . so i avoid to use it

i want not to return before completely getting file via readStream.listen

HKTareen
  • 51
  • 5

0 Answers0