Flutter Web在macOS遇权限拒绝错误,Linux下正常运行
Flutter Web项目在macOS Chrome中出现权限拒绝错误的解决方案
问题描述
Flutter Web项目在Linux系统的Chrome浏览器中可正常运行,但在macOS系统Chrome中抛出以下错误:
FileSystemException: Directory listing failed, path = '/Users/iberkeugur/development/projectname/../../../../usr/sbin/authserver' (OS Error: Permission denied, errno = 13)
环境信息
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.1 22C65 darwin-arm, locale tr-TR) • Flutter version 3.3.10 on channel stable at /Users/iberkeugur/development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 135454af32 (5 weeks ago), 2022-12-15 07:36:55 -0800 • Engine revision 3316dd8728 • Dart version 2.18.6 • DevTools version 2.15.0 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at /Users/iberkeugur/Library/Android/sdk • Platform android-33, build-tools 33.0.1 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14C18 • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) [✓] VS Code (version 1.74.3) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.56.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-arm64 • macOS 13.1 22C65 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.87 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found!
解决方案
- 排查dart:io API的误用:Flutter Web运行在浏览器沙箱中,不允许直接访问本地文件系统。检查代码中是否使用了
dart:io库的目录/文件操作(如Directory.listSync()、File.readAsString()等),替换为Web兼容的API:- 读取项目内置资源:使用
rootBundle.loadString()或AssetImage - 用户文件上传:使用Web专用的文件选择插件
- 读取项目内置资源:使用
- 清理并重新构建项目:执行以下命令清除缓存并重新构建Web产物:
之后重新启动Chrome运行项目flutter clean flutter build web - 检查依赖包兼容性:排查项目依赖是否存在在Web环境下错误调用
dart:io的情况,替换为支持Web的依赖版本
内容的提问来源于stack exchange,提问作者Berke Uğur
相关产品推荐
相关产品推荐

