Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Unsupported operation: Platform._localeName

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?

like image 951
Priyshrm Avatar asked Jun 08 '26 07:06

Priyshrm


1 Answers

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.

like image 88
Valentin Vignal Avatar answered Jun 11 '26 22:06

Valentin Vignal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!