3

Web アプリケーションに Flutter Web を使用していますが、イメージをサーバーにアップロードするためにイメージ ピッカーからファイルに変換するのに問題があります。Image.file(xxx) に画像を表示しますが、次のエラーが表示されます。

アセットの読み込み中にエラーが発生しました: FormatException: Illegal scheme character (at character 6) Image(image:%20MemoryImage(Uint8List%234267a,%20scale:%201),%20frameBuilder...

ここに私が試しているコードがあります:

Future getImage(bool isCamera) async {

    Image image;

    if (isCamera) {
      image = await FlutterWebImagePicker.getImage;
    } else {
    }

     var bytes = await rootBundle.load('$image');
    String tempPath = (await getTemporaryDirectory()).path;
    File file = File('$tempPath/profile.png');

    await file.writeAsBytes(
        bytes.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes));


    setState(() {
      currentSelfie = file;
      _accDetails['customer_selfie'] = currentSelfie;
    });
  }

前もって感謝します

4

2 に答える 2

0

I havent used the plugin although your code has 2 issues. One is the if statement and the second one is using Rootbundle. If you are picking from the filesystem, my assumption isCamera would be false. You have not added any logic for the falsy condition.

 if (isCamera) {// This would be true if the source was camera
  image = await FlutterWebImagePicker.getImage;
 } else {

 }

Additionally,

var bytes = await rootBundle.load('$image');

From the flutter documentation, rootbundle contains the resources that were packaged with the application when it was built. Those are assets that you define in your pubspec. yaml. You are selecting an image at runtime hence its not bundled as an asset.

Since the package appears to return an image object, use the toByteData method on the image i.e

image = await FlutterWebImagePicker.getImage;
await image.toByteData();//This method has some parameters. Look into them
于 2020-08-09T23:50:20.770 に答える