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
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 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) {
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 {
@chalin
chalin / main.dart
Created June 5, 2018 09:03
Language Tour: Restricting the parameterized type
// From https://www.dartlang.org/guides/language/language-tour#restricting-the-parameterized-type
class SomeBaseClass {}
// T must be SomeBaseClass or one of its descendants.
class Foo<T extends SomeBaseClass> {
String toString() => 'Foo<$T>';
}
class Extender extends SomeBaseClass {}
@chalin
chalin / main.dart
Created June 6, 2018 20:29
Uri.queryParametersAll() Dart 2 type error
void main() {
var uri = Uri.parse('https://foo.bar.com/this/is/a/path?foo=foo1&foo=foo2&bar=baz');
print(uri);
print(uri.queryParameters);
// print(uri.queryParametersAll); // -> uncomment to see type error
}
@chalin
chalin / index.html
Created June 26, 2018 15:07
its_all_about_you with dart2js error
<!DOCTYPE html>
<!--
Copyright (c) 2012, 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.
-->