Skip to content

Commit

Permalink
update everything for dart 2
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpryan committed Jan 10, 2019
1 parent fde8ea1 commit c9fcef5
Show file tree
Hide file tree
Showing 51 changed files with 424 additions and 884 deletions.
5 changes: 5 additions & 0 deletions Makefile
@@ -0,0 +1,5 @@
.PHONY: build
build:
pub run build_runner build --release --output build
rm -r docs
mv build/web docs
7 changes: 7 additions & 0 deletions README.md
@@ -0,0 +1,7 @@
Source code for [Dart By Example](http://jpryan.me/dartbyexample).

## Building

```
pub run build_runner build --release --output build/
```
26 changes: 10 additions & 16 deletions docs/examples/async_await/index.html
@@ -1,31 +1,22 @@
<html>
<head>
<title>Dart by example</title>
<title>Dart by example: Async &#x2F; Await</title>
<link rel="stylesheet" href="../../site.css">
<link rel="stylesheet" href="../../hljs/styles/mono-blue.css">
<script src="../../hljs/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="example">
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-WLPW3F"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WLPW3F');</script>
<!-- End Google Tag Manager -->
<h2><a href="../../">Dart By Example: </a> Async / Await</h2>
<pre>
<h2><a href="/">Dart by Example</a>: Async &#x2F; Await</h2>
<pre>
<code class="hljs dart">import 'dart:async';

const Duration delay = const Duration(milliseconds: 200);

// This function doesn't use async / await; just the
// standard Future API
Future&lt;String&gt; loadLastName(String firstName) {
Future<String> loadLastName(String firstName) {
return new Future.delayed(delay).then((_) {
return firstName + 'son';
});
Expand All @@ -34,7 +25,7 @@ <h2><a href="../../">Dart By Example: </a> Async / Await</h2>
// Marking a function with 'async' will return a future
// that completes with the returned value.
// This function is equivalent to [loadLastName]
Future&lt;String&gt; loadLastName2(String firstName) async {
Future<String> loadLastName2(String firstName) async {
await new Future.delayed(delay);

return firstName + 'son';
Expand All @@ -51,13 +42,16 @@ <h2><a href="../../">Dart By Example: </a> Async / Await</h2>
}
</code>
</pre>
<pre><code class="bash">$ dart async_await.dart
<pre><code class="language-bash">$ dart async_await.dart
greg gregson
steve steveson
</code></pre>


<div class="footer">
<p>by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a></p>

by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a>

</div>
</div>
</body>
28 changes: 11 additions & 17 deletions docs/examples/async_star/index.html
@@ -1,24 +1,15 @@
<html>
<head>
<title>Dart by example</title>
<title>Dart by example: Async*</title>
<link rel="stylesheet" href="../../site.css">
<link rel="stylesheet" href="../../hljs/styles/mono-blue.css">
<script src="../../hljs/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="example">
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-WLPW3F"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WLPW3F');</script>
<!-- End Google Tag Manager -->
<h2><a href="../../">Dart By Example: </a> Async*</h2>
<pre>
<h2><a href="/">Dart by Example</a>: Async*</h2>
<pre>
<code class="hljs dart">import 'dart:async';

main() async {
Expand All @@ -27,14 +18,14 @@ <h2><a href="../../">Dart By Example: </a> Async*</h2>
}
}

Stream&lt;String&gt; printNumbersDownAsync(int n) async* {
Stream<String> printNumbersDownAsync(int n) async* {
int k = n;
while (k &gt;= 0) {
while (k >= 0) {
yield await loadMessageForNumber(k--);
}
}

Future&lt;String&gt; loadMessageForNumber(int i) async {
Future<String> loadMessageForNumber(int i) async {
await new Future.delayed(new Duration(milliseconds: 50));
if (i % 2 == 0) {
return '$i is even';
Expand All @@ -44,7 +35,7 @@ <h2><a href="../../">Dart By Example: </a> Async*</h2>
}
</code>
</pre>
<pre><code class="bash">$ dart async_star.dart
<pre><code class="language-bash">$ dart async_star.dart
5 is odd
4 is even
3 is odd
Expand All @@ -55,6 +46,9 @@ <h2><a href="../../">Dart By Example: </a> Async*</h2>


<div class="footer">
<p>by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a></p>

by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a>

</div>
</div>
</body>
26 changes: 10 additions & 16 deletions docs/examples/await_for/index.html
@@ -1,24 +1,15 @@
<html>
<head>
<title>Dart by example</title>
<title>Dart by example: Await For</title>
<link rel="stylesheet" href="../../site.css">
<link rel="stylesheet" href="../../hljs/styles/mono-blue.css">
<script src="../../hljs/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="example">
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-WLPW3F"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WLPW3F');</script>
<!-- End Google Tag Manager -->
<h2><a href="../../">Dart By Example: </a> Await For</h2>
<pre>
<h2><a href="/">Dart by Example</a>: Await For</h2>
<pre>
<code class="hljs dart">import 'dart:async';

main() async {
Expand All @@ -27,15 +18,15 @@ <h2><a href="../../">Dart By Example: </a> Await For</h2>
}
}

Stream&lt;int&gt; numbersDownFrom(int n) async* {
while (n &gt;= 0) {
Stream<int> numbersDownFrom(int n) async* {
while (n >= 0) {
await new Future.delayed(new Duration(milliseconds: 100));
yield n--;
}
}
</code>
</pre>
<pre><code class="bash">$ dart await_for.dart
<pre><code class="language-bash">$ dart await_for.dart
5 bottles of beer
4 bottles of beer
3 bottles of beer
Expand All @@ -46,6 +37,9 @@ <h2><a href="../../">Dart By Example: </a> Await For</h2>


<div class="footer">
<p>by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a></p>

by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a>

</div>
</div>
</body>
22 changes: 8 additions & 14 deletions docs/examples/classes/index.html
@@ -1,24 +1,15 @@
<html>
<head>
<title>Dart by example</title>
<title>Dart by example: Classes</title>
<link rel="stylesheet" href="../../site.css">
<link rel="stylesheet" href="../../hljs/styles/mono-blue.css">
<script src="../../hljs/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="example">
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-WLPW3F"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WLPW3F');</script>
<!-- End Google Tag Manager -->
<h2><a href="../../">Dart By Example: </a> Classes</h2>
<pre>
<h2><a href="/">Dart by Example</a>: Classes</h2>
<pre>
<code class="hljs dart">import 'dart:math';

class Position {
Expand Down Expand Up @@ -47,12 +38,15 @@ <h2><a href="../../">Dart By Example: </a> Classes</h2>
}
</code>
</pre>
<pre><code class="bash">$ dart classes.dart
<pre><code class="language-bash">$ dart classes.dart
7.810249675906654
</code></pre>


<div class="footer">
<p>by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a></p>

by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a>

</div>
</div>
</body>
22 changes: 8 additions & 14 deletions docs/examples/comments/index.html
@@ -1,24 +1,15 @@
<html>
<head>
<title>Dart by example</title>
<title>Dart by example: Comments</title>
<link rel="stylesheet" href="../../site.css">
<link rel="stylesheet" href="../../hljs/styles/mono-blue.css">
<script src="../../hljs/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="example">
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-WLPW3F"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WLPW3F');</script>
<!-- End Google Tag Manager -->
<h2><a href="../../">Dart By Example: </a> Comments</h2>
<p>Dartdoc parses comments starting with <code>///</code>.
<h2><a href="/">Dart by Example</a>: Comments</h2>
<p>Dartdoc parses comments starting with <code>///</code>.
Multiple-line comments and single-line comments
use <code>/* */</code> and <code>//</code>, respectively</p><pre>
<code class="hljs dart">/// Represents a two-dimensional position
Expand All @@ -43,12 +34,15 @@ <h2><a href="../../">Dart By Example: </a> Comments</h2>
}
</code>
</pre>
<pre><code class="bash">$ dart comments.dart
<pre><code class="language-bash">$ dart comments.dart
Position
</code></pre>


<div class="footer">
<p>by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a></p>

by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a>

</div>
</div>
</body>
24 changes: 9 additions & 15 deletions docs/examples/const/index.html
@@ -1,46 +1,40 @@
<html>
<head>
<title>Dart by example</title>
<title>Dart by example: Constants</title>
<link rel="stylesheet" href="../../site.css">
<link rel="stylesheet" href="../../hljs/styles/mono-blue.css">
<script src="../../hljs/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="example">
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-WLPW3F"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WLPW3F');</script>
<!-- End Google Tag Manager -->
<h2><a href="../../">Dart By Example: </a> Constants</h2>
<p>In dart, compile-time constants can be created as long
<h2><a href="/">Dart by Example</a>: Constants</h2>
<p>In dart, compile-time constants can be created as long
as the object's deep structure can be determined at compile time.</p><pre>
<code class="hljs dart">import 'dart:math';

// compile-time constants are defined using 'const'
const name = "greg";

// Objects can also be declared at compile-time
const Rectangle&lt;int&gt; bounds = const Rectangle(0, 0, 5, 5);
const Rectangle<int> bounds = const Rectangle(0, 0, 5, 5);

main() {
print(name);
print(bounds);
}
</code>
</pre>
<pre><code class="bash">$ dart const.dart
<pre><code class="language-bash">$ dart const.dart
greg
Rectangle (0, 0) 5 x 5
</code></pre>


<div class="footer">
<p>by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a></p>

by <a href="http://twitter.com/jryanio">@jryanio</a> | <a href="http://github.com/johnpryan/dartbyexample">source</a> | <a href="https://github.com/johnpryan/dartbyexample/blob/master/LICENSE">license</a>

</div>
</div>
</body>

0 comments on commit c9fcef5

Please sign in to comment.