flutter - 错误:不支持的操作:Platform._localeName
问题描述
我正在使用 dart.io 包并尝试像这样使用 Platform.localeName 检测系统的当前位置
WidgetsFlutterBinding.ensureInitialized();
String defaultSystemLocale = Platform.localeName;
print('$defaultSystemLocale');
但是当我在 Chrome (Web) 中运行应用程序时,我收到了这个错误
Error: Unsupported operation: Platform._localeName
at Object.throw_ [as throw] (http://localhost:62284/dart_sdk.js:5061:11)
at Function._localeName (http://localhost:62284/dart_sdk.js:54692:17)
at Function.localeName (http://localhost:62284/dart_sdk.js:54698:71)
at Function.get localeName [as localeName] (http://localhost:62284/dart_sdk.js:54574:27)
at main (http://localhost:62284/packages/testapp/main4.dart.lib.js:97:45)
知道为什么吗?
解决方案
如果您Platform
来自dart:io
,则网络不支持(请参阅此网站)。您可以改为从universal_io导入它。
推荐阅读
- python - 我正在尝试绘制具有独特颜色但出现错误的集群
- amazon-web-services - 如何从 Bitbucket 部署到 AWS 到不同的实例和不同的文件夹?
- html - 如何使用 express 发送带有 css 的 html 文件作为对连接客户端的响应
- javascript - 将响应缓冲区转换为 JSON
- awt - 在无头 linux 服务器上获取系统剪贴板的内容以进行自动化测试
- ios - 无法将“__NSSingleObjectArrayI”类型的值转换为“NSString”
- spring-boot-actuator - 即使网络连接断开,Spring boot RabbitMq 健康检查也会报告 UP
- javascript - Cordova InAppBowser 在执行脚本后未加载每个页面结果的 DOM
- vim - 禁用语法高亮,但仅适用于一种文件类型
- javascript - 我是否正确地编写了我的 JavaScript 网络动画?