【问题标题】:How to copy the path of image and store it in? Error:- The method copy isnt defined fo type 'PickedFile'如何复制图像的路径并将其存储在其中?错误:- 没有为类型“PickedFile”定义方法副本
【发布时间】:2020-10-05 16:11:16
【问题描述】:

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

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】:

    你应该复制_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');
          }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多