我已经搜索了互联网,并且正在做每个人都说要做的事情

我已经在互联网上搜索并按照每个人所说的做,但由于某种原因,我无法将文件图像或其他文件保存到应用程序文件夹中。

我有这个方法来获取应用目录…

Future get _localAppPath async {
    Directory? directory;
    if (Platform.isAndroid) {
      directory = await getApplicationDocumentsDirectory();

图片[1]-我已经搜索了互联网,并且正在做每个人都说要做的事情-唐朝资源网

Utilities.logInfo('Local Android App Path is: ${directory.path}'); } else { // if IOS Device directory = await getTemporaryDirectory(); Utilities.logInfo('Local IOS App Path is: $directory'); }

图片[2]-我已经搜索了互联网,并且正在做每个人都说要做的事情-唐朝资源网

return directory; }

我在我的保存方法中使用它…

  Future saveProfileImageLocally(File _file) async {
    try {

图片[3]-我已经搜索了互联网,并且正在做每个人都说要做的事情-唐朝资源网

final appDirPath = await _localAppPath; //Utilities.logWarning('New path is: ${appDirPath.path}'); final fileExt = extension(_file.path); // Check is directory exists Utilities.logWarning('FilePath: ${_file.path}'); File newFile = await _file.rename('${appDirPath.path}/images/profileImage$fileExt'); Utilities.logWarning('New path is: ${newFile.path}'); Storage.saveValue('profileImage', newFile.path); } catch (e) { Utilities.logError(e.toString()); } }

每次应用程序启动时我都会检查权限,所以我知道我有权限,但无论我不断收到此错误,没有这样的文件或目录…在阅读另一篇 stackoverflow 帖子之前,我一直在尝试使用复制功能。

FileSystemException: Cannot rename file to '/data/user/0/ca.company.example/app_flutter/images/profileImage.jpg', path = '/data/user/0/ca.company/example/cache/CAP370489784397780451.jpg' (OS Error: No such file or directory, errno = 2)

这应该是我在网上阅读的所有资源和教程中的一个简单的单行过程……所以我很困惑我错过了哪一步。

任何帮助将不胜感激。

© 版权声明
THE END
喜欢就支持一下吧
点赞242赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容