Flutter 在android 10中不允许将图像保存到Flatter中的本地目录

Flutter 在android 10中不允许将图像保存到Flatter中的本地目录,flutter,flutter-dependencies,flutter-packages,flutter-image,Flutter,Flutter Dependencies,Flutter Packages,Flutter Image,我正在尝试将图像保存到电话本地目录。在这里,我使用这个软件包。这是我的密码 class DownloadImage { Future writeToDownloadPath(GridImage imageData) async { try { var imageId = await ImageDownloader.downloadImage(imageData.url ,destination: AndroidDestinationType.custom

我正在尝试将图像保存到电话本地目录。在这里,我使用这个软件包。这是我的密码

class DownloadImage {

  Future writeToDownloadPath(GridImage imageData) async {

    try {

      var imageId = await ImageDownloader.downloadImage(imageData.url
      ,destination: AndroidDestinationType.custom(directory: 'motivational Quotes', 
      inPublicDir: true ,subDirectory: '/motivational Quotes${imageData.location}'));

      print('imageId' + imageId.toString());

      if (imageId == null) {
        return;
      }

    } catch(e) {
      print(e.toString());
    }
  }

}
当我在Android 10设备上运行并尝试下载图像时,它会给我这个错误

E/MethodChannel#plugins.ko2ic.com/image_downloader(25282): java.lang.IllegalStateException: Not one of standard directories: motivational Quotes
我已经在AndroidManifest中添加了android:requestLegacyExternalStorage=“true”,并在build.gradle文件中将targetSdkVersion和compileSdkVersion设置为29。我确实清理并运行了代码,但问题仍然是一样的

格雷德尔先生

defaultConfig {

    applicationId "com.example.app
    minSdkVersion 21
    targetSdkVersion 29
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
}
雄激素单

<application
      android:name="io.flutter.app.FlutterApplication"
      android:label="Motivational Quotes"
      android:icon="@mipmap/ic_launcher"
      android:requestLegacyExternalStorage="true">


如果有人能帮我解决这个问题,我将不胜感激。谢谢

此目录中只有4个标准目录

因此,您必须在此处进行更改:


 var imageId = await ImageDownloader.downloadImage(imageData.url
      ,destination: AndroidDestinationType.custom(directory: 'motivational Quotes', 
      inPublicDir: true ,subDirectory: '/motivational Quotes${imageData.location}'));

我建议您保持简单,如下所示:


 destination: AndroidDestinationType.directoryPictures
                        ..inExternalFilesDir()
                        ..subDirectory('${imageData.location}'),


我在Android10中也遇到了同样的问题,我认为保存在自定义目录中的功能与Android10不兼容。同样的代码也适用于其他人

谢谢您的回答。是的,它以这种方式下载图像,但它存储在“/storage/emulated/0/Android/data//files`”中。但我想在手机图库中看到下载的图像。因此,我必须将图像保存在dowload文件夹或任何其他指定文件夹中。你能给我一个解决办法吗。如果你能帮我解决这个问题,我将不胜感激

 destination: AndroidDestinationType.directoryPictures
                        ..inExternalFilesDir()
                        ..subDirectory('${imageData.location}'),