Skip to content

Instantly share code, notes, and snippets.

@chalin
chalin / chrome-output.txt
Created March 19, 2014 16:36
Reading `InputElement.valueAsDate` results in NullError (Cannot call "getTime" on null), but should just be null value
# Clicking on each link yields:
number.value => ''
number.valueAsNumber => NaN
number.valueAsDate => Exception: NullError: Cannot call "getTime" on null
date.value => ''
date.valueAsNumber => NaN
date.valueAsDate => Exception: NullError: Cannot call "getTime" on null
time.value => ''
time.valueAsNumber => NaN
time.valueAsDate => Exception: NullError: Cannot call "getTime" on null
@chalin
chalin / main.dart
Created May 24, 2016 18:25
HtmlElement `style` property naming in Dart
import 'dart:html';
void main() {
var div = document.createElement('div');
print('1. div.style.fontSize = ${div.style.fontSize}');
div.style.fontSize = "120%";
print('2. div.style.fontSize = ${div.style.fontSize}');
/*
* div.style[] results in warning:
* The operator '[]=' is not defined for the class 'CssStyleDeclaration'.
main() => print(new Object() == new Object());
@chalin
chalin / main.dart
Created May 9, 2017 21:38
Todo-list generator for webdev.dartlang.org/guides/get-started
void main() {
thingsTodo().forEach(print);
}
Iterable<String> thingsTodo() sync* {
var actions = ['Walk', 'Wash', 'Feed'];
var pets = ['cats', 'dogs'];
for (var action in actions) {
for (var pet in pets) {
@chalin
chalin / main.dart
Last active June 21, 2017 16:19
Exploring the new Function-keyword based anonymous function-type syntax
typedef FooOrig<T>(T a);
typedef FooNew1 = T Function<T>(T a);
typedef FooNew2<T> = T Function(T a);
typedef FooNew3<T> = T Function<T>(T a);
// DECLARATION // STATIC TYPE
FooOrig vf_orig0; // (dynamic) → dynamic
FooOrig<int> vf_orig1; // (int) → dynamic
T Function<T>(T a) vf_new; // <T>(T) → T
FooNew1 vf_new1a; // <T>(T) → T
@chalin
chalin / main.dart
Created November 10, 2017 15:14
Language Tour: Anonymous Function
void main() {
var list = ['apples', 'bananas', 'oranges'];
list.forEach((item) {
print('${list.indexOf(item)}: $item');
});
}
@chalin
chalin / main.dart
Last active August 14, 2018 00:10 — forked from Sfshaza/main.dart
futures/async-await
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
printDailyNewsDigest() async {
String news = await gatherNewsReports();
print(news);
}
@chalin
chalin / main.dart
Last active August 14, 2018 00:10 — forked from Sfshaza/main.dart
futures/futures-api
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
printDailyNewsDigest() {
final future = gatherNewsReports();
future.then((news) => print(news));
}
main () {
List<dynamic> strings = ["not", "ints"];
List<int> numbers = strings; // <- strong mode error?
for (var number in numbers) {
print(number - 10); // <— Boom!
}
}
@chalin
chalin / main.dart
Last active April 23, 2018 15:14 — forked from Sfshaza/main.dart
streams/throw_error
// Copyright (c) 2015, the Dart project authors.
// Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed
// by a BSD-style license that can be found in the LICENSE file.
import 'dart:async';
Future<int> sumStream(Stream<int> stream) async {
var sum = 0;
try {