如何复制图片的路径并存储在其中?错误:-复制方法没有定义为'PickedFile'类型。

问题描述 投票:0回答:1

这是使用复制功能时出现的错误。如何保存从相机中点击的图像?

Future _takePicture() async {
    final imageFile = await ImagePicker().getImage(
      source: ImageSource.camera,
      maxHeight: 600,
    );
    setState(() {
      _storedImage = File(imageFile.path);
    });
    final appDir = await syspaths.getApplicationDocumentsDirectory();
    final fileName = path.basename(imageFile.path);
    final savedImage = await imageFile.copy('${appDir.path}/$fileName');
  }
flutter dart flutter-image
1个回答
0
投票

你应该复制 _storedImage 而不是 imageFile

imageFile 类型为 PickedFile 并没有 copy 办法

Future _takePicture() async {
        final imageFile = await ImagePicker().getImage(
          source: ImageSource.camera,
          maxHeight: 600,
        );
        setState(() {
          _storedImage = File(imageFile.path);
        });
        final appDir = await syspaths.getApplicationDocumentsDirectory();
        final fileName = path.basename(imageFile.path);
        final savedImage = await _storedImage.copy('${appDir.path}/$fileName');
      }
© www.soinside.com 2019 - 2024. All rights reserved.