简体   繁体   English

在dartium中使用'dart:io'吗? 有什么解决方法吗?

[英]Using 'dart:io' in dartium ? Any work arounds?

I am new to dart and I am trying to read data from a file and use the contents to draw something canvas. 我是dart的新手,正在尝试从文件中读取数据并使用其内容绘制画布。 In doing so I am running into 'The built-in library 'dart:io' is not available on Dartium ' issue. 为此,我遇到了“内置库'dart:io'在Dartium问题上不可用”的情况。

I understand Dart has limitations as Javascript in that code that is running in a browser cannot natively access the File System of the running client. 我了解Dart具有局限性,因为Javascript的原因在于浏览器中运行的代码无法本地访问正在运行的客户端的文件系统。

At the same time are there any tips on how to read a file and also use the contents to write it to canvas? 同时,有关于如何读取文件以及如何使用内容将其写入画布的任何提示吗?

Thanks in advance. 提前致谢。

What kind of application are you trying to build? 您尝试构建什么样的应用程序?
If it runs in the browser the files are usually on the server. 如果它在浏览器中运行,则文件通常在服务器上。
If it is a normal web page you can't access user files. 如果是普通网页,则无法访问用户文件。 There is a sandboxed space accessible to be used by by the code of a webpage. 网页的代码可以使用沙盒空间。
If you build something like a Chrome app you have less limitations. 如果您构建类似Chrome应用程序的产品,则限制会更少。

You definitely can't import 'dart:io' when the could should run in the browser. 当可以在浏览器中运行时,您绝对不能导入“ dart:io”。
The APIs available in the browser can be found in 'dart:html'. 浏览器中可用的API可以在“ dart:html”中找到。

If you want to build a Chrome app this package provides access to the extended API http://pub.dartlang.org/packages/chrome 如果您要构建Chrome应用,则此软件包可提供对扩展API http://pub.dartlang.org/packages/chrome的访问

I fixed my problem by prompting the user to choose the file. 我通过提示用户选择文件来解决问题。 Similar approach as in https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications but using DART. https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications中类似的方法,但使用DART。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM