This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .. | |
class BooksController extends HTTPController { | |
@httpGet | |
Future<Response> getAllBooks() async { | |
var query = new Query<Book>()..join(set: (book) => book.authors); | |
return new Response.ok(await query.fetch()); | |
} | |
// .. | |
// .. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .. | |
class BooksController extends HTTPController { | |
//.. | |
@httpPost | |
Future<Response> addBook(@HTTPBody() Book book) async { | |
var query = new Query<Book>()..values = book; | |
var insertedBook = await query.insert(); | |
// Insert authors from payload | |
await Future.forEach(book.authors, (Author a) async { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// Variables and constants | |
var edition = 2; | |
int year = 2011; | |
const language = 'Dart'; | |
String name; // == null | |
// Number | |
var num1 = 5; | |
var num2 = 10.0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
void main() { | |
List<String> alphabets = 'abcdefghijklmnopqrstuvwxyz'.split(''); | |
var stream = new Stream.fromIterable(alphabets); | |
var count = 1; | |
stream.listen((char) { | |
Timer(Duration(seconds: 1 * count), () { | |
print(char); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// forEach() | |
var fruits = ['banana', 'pineapple', 'watermelon']; | |
fruits.forEach((fruit) => print(fruit)); // => banana pineapple watermelon | |
print('\n---\n'); | |
// map() | |
var mappedFruits = fruits.map((fruit) => 'I love $fruit').toList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span class="clock"></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
var user = { | |
"firstName": "Tom", | |
"age": 25, | |
}; | |
// 1. addAll() | |
user.addAll({ | |
"lastName": "Smith", | |
"age": 26, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io' show Platform; | |
import 'dart:async' show runZoned; | |
import 'package:path/path.dart' show join, dirname; | |
import 'package:shelf/shelf_io.dart' as io; | |
import 'package:shelf_static/shelf_static.dart'; | |
void main() { | |
// Assumes the server lives in bin/ and that `webdev build` ran | |
var pathToBuild = join(dirname(Platform.script.toFilePath()), '..', 'build'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() async { | |
var str1 = 'Lorem'; | |
var str2 = '$str1 ipsum'; // String interpolation | |
var str3 = '''Multi | |
Line | |
$str1 $str2'''; // Multi line string | |
print(str1.contains('rem')); // true | |
print(str2.startsWith('Lorem')); // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
var now = new DateTime.now(); | |
var berlinWallFell = new DateTime.utc(1989, 11, 9); | |
var moonLanding = DateTime.parse('1969-07-20 20:18:04Z'); | |
print(now); | |
print(berlinWallFell); | |
print(moonLanding); | |
print('\n---\n'); |