首页 > 解决方案 > 错误:不支持的操作: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)

知道为什么吗?

标签: flutterflutter-web

解决方案


如果您Platform来自dart:io,则网络不支持(请参阅此网站)。您可以改为从universal_io导入它。


推荐阅读