Dart web apps : read and write text file (to textarea if possible)

548 views
Skip to first unread message

Supakorn Suttiruang

unread,
Jan 18, 2014, 11:57:57 AM1/18/14
to mi...@dartlang.org
Hi all the good-looking Dartisans! :D
I'm trying to use dart:io and I noticed that it's only available with Comman-line apps

Is there anyway to do that in the web apps??

Thank you so much

Allan MacDonald

unread,
Jan 18, 2014, 1:52:41 PM1/18/14
to General Dart Discussion

Yes, you can read the file from local storage, the browser file system, or from the server. Reading from the OS file system is not permitted.

Allan

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Supakorn Suttiruang

unread,
Jan 18, 2014, 9:04:24 PM1/18/14
to mi...@dartlang.org, amacd...@cgsinc.ca
Can you give me more hint on doing the local storage? :) Thank you 

Allan MacDonald

unread,
Jan 18, 2014, 9:19:56 PM1/18/14
to General Dart Discussion
This should be the easiest way. Great library. https://github.com/sethladd/lawndart


Supakorn Suttiruang

unread,
Jan 18, 2014, 9:24:07 PM1/18/14
to mi...@dartlang.org
Thank you so much :)
This Gmail is from Lum.
Gmaiนี้ถูกส่งมาโดย Lum ครับ

Supakorn Suttiruang

unread,
Jan 18, 2014, 10:58:11 PM1/18/14
to mi...@dartlang.org
Hey Allan
Is there a way to save a text from textarea to a file using that lib?

Allan MacDonald

unread,
Jan 19, 2014, 7:23:28 AM1/19/14
to General Dart Discussion
That lawnchair library saves to the localstorage which is more of a client side DB. 

To save to a file, it depends on where the file will be saved. If it is server side, then you can post the contents of the text area to the server and save to a file there. If you want to save to a file on the client machine(their local filesystem on windows for example), you have the sandbox to deal with and do not have direct access to that file system. There is a file system as of HTML5 that you can use to save a file to the virtual filesystem. But that is protected and only available from the client within the browser. It is possible to use other approaches to get the file to the OS filesystem, like having the user download the file. You could also use the Google drive API to save to the cloud, and use the syncing capabilities to migrate the files to the desktop.

What are your requirements?

Supakorn Suttiruang

unread,
Jan 19, 2014, 7:35:07 AM1/19/14
to mi...@dartlang.org
I need to save my text in textarea to a file/open a file into a textarea (save/open file dialog)
but I have no idea how to accomplish that :(

Allan MacDonald

unread,
Jan 19, 2014, 7:44:20 AM1/19/14
to General Dart Discussion
Yes, but is there any requirement for how it is saved, or where it  is saved? Does it have to be a file? Or would a DB be OK?

Supakorn Suttiruang

unread,
Jan 19, 2014, 7:55:56 AM1/19/14
to mi...@dartlang.org
I think it has to be a file because I'm trying to create an open source code editor :)

Allan MacDonald

unread,
Jan 19, 2014, 9:45:18 AM1/19/14
to General Dart Discussion
If your requirement is that users be able to save a copy of their file to their own machine, you can achieve this easily with HTML. If users want to download a copy of the file, and they do that manually, there is no restriction. The restriction is when you want to write to the OS filesystem directly from the Dart code runtime.

You may already know about this, but there are a few pub packages that will help you out. Look at https://www.google.com/url?q=http://pub.dartlang.org/packages/ace&sa=U&ei=9OPbUo3ICY7roAT10oDgDA&ved=0CAcQFjAC&client=internal-uds-cse&usg=AFQjCNH6kcijhO9-bdtKpz-nq50oxBIrww and also have a look at https://www.google.com/url?q=http://pub.dartlang.org/packages/ice_code_editor&sa=U&ei=9OPbUo3ICY7roAT10oDgDA&ved=0CAUQFjAA&client=internal-uds-cse&usg=AFQjCNGASh1KQgOAo-v1E6b4PyE0gD8H6Q. Also, the google team are building an editor using dart as well. You can find out more at https://github.com/dart-lang/spark. There is much to learn from these three if you want to do an editor.

Cheers,

Allan

Supakorn Suttiruang

unread,
Jan 19, 2014, 9:51:00 AM1/19/14
to mi...@dartlang.org
Thank you so much for you suggestions, Allan :D
I'm so excited about Spark! Did you check it out?

Allan MacDonald

unread,
Jan 19, 2014, 10:01:48 AM1/19/14
to General Dart Discussion
Yeah, I really like spark. It has custom polymer widgets, so I borrowed some ideas from them on how to organize and structure my custom widgets, along with other great ideas!

I also like the idea of packaging my web apps as a chrome app eventually, so again, there is a lot of experience with that in Spark as well.

Hope you find it useful! I am sure you will! :)

Supakorn Suttiruang

unread,
Jan 19, 2014, 10:41:57 AM1/19/14
to mi...@dartlang.org
Yeah the web platform is growing so fast !
Reply all
Reply to author
Forward
0 new messages