我正在尝试将图像保存到手机本地目录。在这里,我使用image_downloader包。这是我的代码
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。我确实清理干净并运行了代码,但问题仍然存在。
构建.gradle
defaultConfig {
applicationId "com.example.app
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
AndroidManifest
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Motivational Quotes"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true">
如果有人能帮助我解决这个问题,我将不胜感激。谢谢 !