2
votes

I wrote a Dart web app that compiles to Javascript (dart2js), which I package in an APK (PhoneGap) and run as an Android app. I want my app to backup and restore its data from the local file system.

W3C has a File API standard for file IO within a web browser: http://www.w3.org/TR/FileAPI/#introduction.

A popular HTML5 learning website has an article showing how to use the W3C File API: http://www.html5rocks.com/en/tutorials/file/dndfiles/

I tried to use Dart's dart:io library to write to a file from a web page, but got this error:

Failed to load a file dart:io
 Failed to load resource
   dart:io

I'm not sure what caused this error. Maybe dart:io doesn't run in a browser. Maybe dart:io has an undocumented pubspec dependency (I didn't see any dart:io examples that declare its dependencies.)

If you know how to read/write files in a web browser using Dart, please explain how to do it.

Thanks

1
Dart:io does indeed not run in the browser. From the docs: "The IO library is used for Dart server applications, which run on a stand-alone Dart VM from the command line. This library does not work in browser based applications." - Christophe Herreman
Have you tried using the classes in dart:html? Looks like they are all there and you should be able to use them just like in that article. - Dennis Kaselow

1 Answers

4
votes

dart:io is a Server library, you have to use File from dart:html.