Dartium上没有内置库'dart:io'

5 dart dart-io

我不知道问题出在哪里.将SystemCheck类导入主Dart文件时会出现此错误.

SystemCheck类:

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

在主文件中导入:

import 'cz.felguide.core/system.dart';
Run Code Online (Sandbox Code Playgroud)

Mat*_*t B 4

这是正确的。您不能在 Dartium 中使用dart:io或设计用于在浏览器中运行的代码。对于这个简单的示例,您想要的大部分内容都可以在Navigator 类中找到,例如Navigator.platform

Dart 与 Javascript 具有相同的限制,即在浏览器中运行的代码无法本机访问正在运行的客户端的文件系统。有一些例外,例如专门的 Chrome 打包应用程序仅在 Chrome 中允许某些权限。即使这样,他们也要求应用程序专门请求额外的权限,并由用户授予它们。