【发布时间】:2021-01-29 07:48:38
【问题描述】:
我正在尝试将图像保存到手机本地目录。在这里,我使用 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。我确实清理并运行了代码,但问题仍然存在。
build.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">
如果有人能帮助我解决这个问题,我将不胜感激。谢谢!
【问题讨论】:
标签: flutter flutter-dependencies flutter-packages flutter-image