The built-in library 'dart:io' is not available on Dartium

1.5k views Asked by At

I don't know where is the problem. This error show up when I import my SystemCheck class to main Dart file.

SystemCheck class:

import 'dart:io';
class SystemCheck{  
    getOperatingSystem() => Platform.operatingSystem;
    getUser() => Platform.localHostname;  
}

Import in main file:

import 'cz.felguide.core/system.dart';
1

There are 1 answers

0
Matt B On BEST ANSWER

That's correct. You cannot use dart:io in Dartium or code designed for running in the browser. For this simple example much of what you want can be found in the Navigator class such as Navigator.platform

Dart has the same limitations as Javascript in that code that is running in a browser cannot natively access the File System of the running client. There are some exceptions such as the specialized Chrome Packaged Apps which allow certain permissions just within Chrome. Even then they require the app to specifically request the extra permissions and the user to grant them.