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
// lib/hacker_news_scraper.dart | |
import 'dart:convert'; | |
import 'package:http/http.dart'; | |
import 'package:html/parser.dart'; | |
import 'package:html/dom.dart'; | |
Future initiate() async { | |
// Make API call to Hackernews homepage | |
var client = Client(); |
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:html'; | |
void main() { | |
var vApp = createElement('div', | |
attrs: { | |
'id': 'app', | |
}, | |
children: [ | |
'Hello Cat!', | |
createElement('img', |
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:convert'; | |
import 'dart:html'; | |
import 'dart:async'; | |
main() { | |
// Basic example | |
var result = Future(() => 'Hello World!'); | |
print(result); | |
result.then((data) => print(data)); | |
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 pixel = Phone('Pixel XL', 'Google'); | |
pixel.getDeviceInfo(); | |
pixel.getAllFeatures(); | |
} | |
class FeaturesMixin { | |
bool blueTooth = true; | |
bool dualSim = false; | |
bool NFC = 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 johnny = Person('Johnny', 42) | |
..speak() | |
..name = 'Big Johnny' | |
..speak(); | |
var johnnyB = Person('Johnny', 42); | |
print(johnny == johnnyB); | |
var bob = Employee('Bob', 23, DateTime.now()); |
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
// 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'; | |
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
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
<div> | |
<strong id="days"></strong> | |
<strong id="hours"></strong> | |
<strong id="minutes"></strong> | |
<strong id="seconds"></strong> | |
</div> |