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
// web/console.dart | |
@JS('console') | |
library console; | |
import 'package:js/js.dart'; | |
external void log(dynamic str); |
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'); |
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
<div> | |
<strong id="days"></strong> | |
<strong id="hours"></strong> | |
<strong id="minutes"></strong> | |
<strong id="seconds"></strong> | |
</div> |
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'; | |
import 'dart:convert'; | |
void main() async { | |
var server = await HttpServer.bind('127.0.0.1', 9000); | |
await for (HttpRequest req in server) { | |
if (req.method == 'POST' && req.headers.contentType.toString() == 'application/x-www-form-urlencoded') { | |
var content = await req.transform(Utf8Decoder()).join(); | |
var queryParams = Uri(query: content).queryParameters; |
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'; | |
main() async { | |
var file = File('data.txt'); | |
var contents; | |
if (await file.exists()) { | |
// Read file | |
contents = await file.readAsString(); | |
print(contents); |
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
// Absolute imports | |
import 'dart:html'; | |
// Relative imports | |
import './view.dart'; | |
class ChatRoomView implements View { | |
ChatRoomView(this.params) : _contents = DocumentFragment() { | |
onEnter(); | |
} |
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'; | |
import 'dart:convert'; | |
main() async { | |
var apiUrl = Uri.parse('https://jsonplaceholder.typicode.com/posts'); | |
var client = HttpClient(); // `new` keyword optional | |
// 1. Create request | |
HttpClientRequest request = await client.postUrl(apiUrl); |
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 johnny = Person('Johnny', 42) | |
..speak() | |
..name = 'Big Johnny' | |
..speak(); | |
var johnnyB = Person('Johnny', 42); | |
print(johnny == johnnyB); | |
var bob = Employee('Bob', 23, DateTime.now()); |