Home > Software design >  Error: Unsupported operation: Platform._localeName
Error: Unsupported operation: Platform._localeName

Time:11-11

I am using dart.io package and trying to detect the current locate of the system using Platform.localeName like this

WidgetsFlutterBinding.ensureInitialized();
String defaultSystemLocale = Platform.localeName;
print('$defaultSystemLocale');

But when I run the app in Chrome (Web), I am getting this error

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)

Any idea why?

CodePudding user response:

If you are getting Platform from dart:io, it is not supported on web (see this website). You can import it from universal_io instead.

  • Related