Search code examples
dartdart-io

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


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';

Solution

  • 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.