gpt4 book ai didi

Flutter:未处理的异常:FileSystemException:创建失败,路径 = 'Directory: ' '(操作系统错误:只读文件系统,errno = 30)

转载 作者:行者123 更新时间:2023-12-04 15:08:45 26 4
gpt4 key购买 nike

我已经在谷歌上搜索,我发现的解决方案正在使用 path_provider , 在 AndroidManifest.xml 添加权限是的,我已经尝试过了。但我的仍然错误。
这是我的功能

  Future<File> _takePicture() async {
Directory root = await getTemporaryDirectory(); // this is using path_provider
String directoryPath = '$root/bozzetto_camera';
await Directory(directoryPath).create(recursive: true); // the error because of this line
String filePath = '$directoryPath/${DateTime.now()}.jpg';
try {
await _cameraController.takePicture(filePath);
} catch (e) {
return null;
}
return File(filePath);
}
这是我的 AndroidManifest.xml
    <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
...
android:requestLegacyExternalStorage="true">

...

</application>
这是完整的日志。
E/flutter (14879): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FileSystemException: Creation failed, path = 'Directory: '' (OS Error: Read-only file system, errno = 30)
E/flutter (14879): #0 _Directory.create.<anonymous closure> (dart:io/directory_impl.dart:117:11)
E/flutter (14879): #1 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (14879): #2 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (14879): #3 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter (14879): #4 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter (14879): #5 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter (14879): #6 Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter (14879): #7 Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
E/flutter (14879): #8 _rootRun (dart:async/zone.dart:1190:13)
E/flutter (14879): #9 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (14879): #10 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (14879): #11 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter (14879): #12 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (14879): #13 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

最佳答案

您需要修改目录路径。
只需更改代码

String directoryPath = '$root/bozzetto_camera';

String directoryPath = root.path + '/bozzetto_camera';

关于Flutter:未处理的异常:FileSystemException:创建失败,路径 = 'Directory: ' '(操作系统错误:只读文件系统,errno = 30),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65613148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com