OLD | NEW |
1 --- | 1 --- |
2 layout: default | 2 layout: default |
3 title: "Connect Dart & HTML" | 3 title: "Connect Dart & HTML" |
4 description: "Shows basic scaffolding of a Dart web app" | 4 description: "Shows basic scaffolding of a Dart web app" |
5 has-permalinks: true | 5 has-permalinks: true |
6 tutorial: | 6 tutorial: |
7 id: connect-dart-html | 7 id: connect-dart-html |
8 next: add-elements | 8 next: add-elements/ |
9 next-title: "Add Elements to the DOM" | 9 next-title: "Add Elements to the DOM" |
10 prev: get-started | 10 prev: get-started/ |
11 prev-title: "Get Started" | 11 prev-title: "Get Started" |
12 --- | 12 --- |
13 | 13 |
14 {% capture whats_the_point %} | 14 {% capture whats_the_point %} |
15 | 15 |
16 * The DOM models a browser page in a tree/node structure. | 16 * The DOM models a browser page in a tree/node structure. |
17 * An HTML file hosts your Dart code in a browser page. | 17 * An HTML file hosts your Dart code in a browser page. |
18 * Use query() with an ID to get an element from the DOM. | 18 * Use query() with an ID to get an element from the DOM. |
19 * Control run-time configurations in Dart Editor with named launches. | 19 * Control run-time configurations in Dart Editor with named launches. |
20 * Compile to JavaScript to run in any modern browser. | 20 * Compile to JavaScript to run in any modern browser. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 Dart Editor creates a directory called mini and, within it, | 160 Dart Editor creates a directory called mini and, within it, |
161 the files and directories needed for a web application. | 161 the files and directories needed for a web application. |
162 | 162 |
163 <img src="images/new-app-files.png" | 163 <img src="images/new-app-files.png" |
164 alt="After new application created"> | 164 alt="After new application created"> |
165 | 165 |
166 * The top-level directory is named after the application. | 166 * The top-level directory is named after the application. |
167 | 167 |
168 * The pubspec.yaml file is used by applications | 168 * The pubspec.yaml file is used by applications |
169 that rely on external packages of Dart code. | 169 that rely on external packages of Dart code. |
170 [Target 5: Install Shared Packages](/docs/tutorials/packages/) | 170 [Target 5: Install Shared Packages](/docs/tutorials/shared-pkgs/) |
171 provides more information. | 171 provides more information. |
172 Web applications use a package called `browser`. | 172 Web applications use a package called `browser`. |
173 This dependency is declared in the pubspec.yaml file. | 173 This dependency is declared in the pubspec.yaml file. |
174 | 174 |
175 * The web directory contains the Dart, HTML, and CSS code for the web app. | 175 * The web directory contains the Dart, HTML, and CSS code for the web app. |
176 | 176 |
177 * The main source file, mini.dart in this sample, | 177 * The main source file, mini.dart in this sample, |
178 contains boilerplate code for the clickme app | 178 contains boilerplate code for the clickme app |
179 you saw in the previous target. | 179 you saw in the previous target. |
180 You will edit the code in this file and | 180 You will edit the code in this file and |
(...skipping 29 matching lines...) Expand all Loading... |
210 <img src="images/0-mini-code-walk-through.png" | 210 <img src="images/0-mini-code-walk-through.png" |
211 alt="Import Dart HTML library"> | 211 alt="Import Dart HTML library"> |
212 | 212 |
213 This program imports Dart's HTML library, | 213 This program imports Dart's HTML library, |
214 which contains the classes and functions for programming the DOM. | 214 which contains the classes and functions for programming the DOM. |
215 Generally speaking, all Dart web apps need the Dart HTML library. | 215 Generally speaking, all Dart web apps need the Dart HTML library. |
216 Key classes include: | 216 Key classes include: |
217 | 217 |
218 | Dart class | Description | | 218 | Dart class | Description | |
219 |---|---| | 219 |---|---| |
220 | <a href="http://api.dartlang.org/dart_html/Node.html" target="_blank">Node</a>
| Implements a Dart Node. | | 220 | <a href="https://api.dartlang.org/dart_html/Node.html" target="_blank">Node</a
> | Implements a Dart Node. | |
221 | <a href="http://api.dartlang.org/dart_html/Element.html" target="_blank">Eleme
nt</a> | A subclass of Node, implements a web page element. | | 221 | <a href="https://api.dartlang.org/dart_html/Element.html" target="_blank">Elem
ent</a> | A subclass of Node, implements a web page element. | |
222 | <a href="http://api.dartlang.org/dart_html/Document.html" target="_blank">Docu
ment</a> | Another subclass of Node. Implements the document object. | | 222 | <a href="https://api.dartlang.org/dart_html/Document.html" target="_blank">Doc
ument</a> | Another subclass of Node. Implements the document object. | |
223 {: .table} | 223 {: .table} |
224 | 224 |
225 The Dart core library contains another useful class, | 225 The Dart core library contains another useful class, |
226 <a href="http://api.dartlang.org/dart_core/List.html" target="_blank">List</a>, | 226 <a href="https://api.dartlang.org/dart_core/List.html" target="_blank">List</a>, |
227 a parameterized class that can specify the type of its members. | 227 a parameterized class that can specify the type of its members. |
228 The Element class keeps its list of child Elements | 228 The Element class keeps its list of child Elements |
229 in a List\<Element>, a list that can contain only Element objects. | 229 in a List\<Element>, a list that can contain only Element objects. |
230 | 230 |
231 ###Using the query() function | 231 ###Using the query() function |
232 | 232 |
233 This app's main() function contains a single | 233 This app's main() function contains a single |
234 line of code that is a little like a run-on sentence | 234 line of code that is a little like a run-on sentence |
235 with multiple things happening one after another. | 235 with multiple things happening one after another. |
236 Let's deconstruct it. | 236 Let's deconstruct it. |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 and then click the Run button | 379 and then click the Run button |
380 <img src="images/run.png" width="16" height="16" | 380 <img src="images/run.png" width="16" height="16" |
381 alt="Run button">. | 381 alt="Run button">. |
382 Dart Editor invokes Dartium | 382 Dart Editor invokes Dartium |
383 and loads `mini.html` in it. | 383 and loads `mini.html` in it. |
384 Below is mini app running in a frame. | 384 Below is mini app running in a frame. |
385 The app just displays a line of text. | 385 The app just displays a line of text. |
386 | 386 |
387 <iframe class="running-app-frame" | 387 <iframe class="running-app-frame" |
388 style="height:150px;width:300px;" | 388 style="height:150px;width:300px;" |
389 src="http://dart-lang.github.com/dart-tutorials-samples/web/target02/min
i/web/mini.html"> | 389 src="http://dart-lang.github.io/dart-tutorials-samples/web/target02/mini
/web/mini.html"> |
390 </iframe> | 390 </iframe> |
391 | 391 |
392 The Dart web app changed | 392 The Dart web app changed |
393 the text in the browser window dynamically at runtime. | 393 the text in the browser window dynamically at runtime. |
394 Of course, placing static text on a browser page | 394 Of course, placing static text on a browser page |
395 and doing nothing else | 395 and doing nothing else |
396 could be accomplished with straight HTML. | 396 could be accomplished with straight HTML. |
397 This little app only shows you how to make a connection | 397 This little app only shows you how to make a connection |
398 from a Dart app to a browser page. | 398 from a Dart app to a browser page. |
399 | 399 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 alt="HTML with CSS"> | 525 alt="HTML with CSS"> |
526 | 526 |
527 Save your files and run the app again. | 527 Save your files and run the app again. |
528 | 528 |
529 Below is the revised mini app, | 529 Below is the revised mini app, |
530 which is slightly more colorful | 530 which is slightly more colorful |
531 but still neither interactive nor interesting. | 531 but still neither interactive nor interesting. |
532 | 532 |
533 <iframe class="running-app-frame" | 533 <iframe class="running-app-frame" |
534 style="height:150px;width:300px;" | 534 style="height:150px;width:300px;" |
535 src="http://dart-lang.github.com/dart-tutorials-samples/web/target02/min
i_with_style/web/mini_with_style.html"> | 535 src="http://dart-lang.github.io/dart-tutorials-samples/web/target02/mini
_with_style/web/mini_with_style.html"> |
536 </iframe> | 536 </iframe> |
537 | 537 |
538 ##About CSS selectors {#about-css-selectors} | 538 ##About CSS selectors {#about-css-selectors} |
539 | 539 |
540 IDs, classes, and other information about elements | 540 IDs, classes, and other information about elements |
541 are established in HTML. | 541 are established in HTML. |
542 Your Dart code can use this information | 542 Your Dart code can use this information |
543 to get elements using a CSS selector—a pattern | 543 to get elements using a CSS selector—a pattern |
544 used to select matching elements in the DOM. | 544 used to select matching elements in the DOM. |
545 CSS selectors allow the CSS, HTML, and Dart code | 545 CSS selectors allow the CSS, HTML, and Dart code |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 where you'll find many recipes about | 637 where you'll find many recipes about |
638 manipulating the DOM and using CSS. | 638 manipulating the DOM and using CSS. |
639 The cookbook also has recipes about basic Dart data types, | 639 The cookbook also has recipes about basic Dart data types, |
640 such strings, lists, maps, and numbers. | 640 such strings, lists, maps, and numbers. |
641 </li> | 641 </li> |
642 </ul> | 642 </ul> |
643 | 643 |
644 {% endcapture %} | 644 {% endcapture %} |
645 | 645 |
646 {% include tutorial.html %} | 646 {% include tutorial.html %} |
OLD | NEW |