-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
DART Cookbook
By :
This recipe shows you the simplest ways to download a file through code, first in a command-line application and then from a web application. As an example, we download the front page of the Learning Dart website from http://learningdart.org.
A client program (be it web or command-line) receives content, such as files or web pages, from a web server using the HTTP protocol. The dart:html and dart:io package provides us with the basic classes we need to do this, which are as follows:
The Uriclass class (from dart:core) has all we need to parse, encode, and decode web addresses; the method Uri.parse is often used
The HttpRequest class (from dart:html) has the getString method to fetch a file from a URL
The HttpClientclass class (from dart:io) has all kinds of methods, such as get and post, to send a request (class HttpClientRequest) to a web server and get a response (class HttpClientResponse) back
For a web app, this is shown in download_string.dart...
Change the font size
Change margin width
Change background colour