Display selected image in Flutter Web

Aur*_*tas 3 image file show flutter-web

Since flutter web is in tech preview, none of the plugins are working.

I have a task to show image, which we select. I have following picker

_startFilePicker() async {
InputElement uploadInput = FileUploadInputElement();
uploadInput.multiple = true;
uploadInput.click();

uploadInput.onChange.listen((e) {
  // read file content as dataURL
  final files = uploadInput.files;
  if (files.length == 1) {
    final file = files[0];
    final reader = FileReader();

    reader.onLoadEnd.listen((e) {
      _handleResult(reader.result);
          });
          reader.readAsDataUrl(file);
        }
      });
      }

        void _handleResult(Object result) {
          setState(() {
            images.add(result);
          });
        }
Run Code Online (Sandbox Code Playgroud)

result gives me output data:image/jpeg;base64,/9j/4AAQSkZJRg....

How can I display this output in Image Widget?

I tried using Image.memory(base64Decode(file)). But file could't be decoded. I suspect because it's not raw base64.

How could I convert this output to visible image? And how to deal with multiple images too?

谢谢

chu*_*han 7

在 base64 字符串中,排除“data:image/jpeg;base64”,只保留“/9j/4AAQSkZJRg...”

将您的 base64 字符串粘贴到在线图像转换器 https://codebeautify.org/base64-to-image-converter,以确保您的 base64 字符串正确

_base64 = "/9j/4AAQSkZJRg...";
Run Code Online (Sandbox Code Playgroud)

解码

Uint8List bytes = base64Decode(_base64);
Run Code Online (Sandbox Code Playgroud)

并显示图像

Image.memory(bytes);
Run Code Online (Sandbox Code Playgroud)

你也可以参考这个How to convert BASE64 string into Image with Flutter?