Skip to content

Instantly share code, notes, and snippets.

import 'dart:convert';
import 'dart:html';
void main() {
_getIPAddress() async {
final url = 'https://httpbin.org/ip';
var request = await HttpRequest.request(url);
String ip = json.decode(request.responseText)['origin'];
print(ip);
}
@chalin
chalin / main.dart
Last active December 5, 2018 18:20
Flutter for React Native devs: Dart Futures
import 'dart:convert';
import 'dart:html';
void main() {
_getIPAddress() {
final url = 'https://httpbin.org/ip';
Future<HttpRequest> request = HttpRequest.request(url);
request.then((value) {
print(json.decode(value.responseText)['origin']);
}).catchError((error) => print(error));
@chalin
chalin / main.dart
Created August 3, 2018 16:03
Sound Dart example
void printInts(List<int> a) => print(a);
void main() {
var list = <int>[]; // Removing <int> results in a type error
list.add(1);
list.add(2);
printInts(list);
}
@chalin
chalin / index.html
Last active October 3, 2019 21:47 — forked from Sfshaza/index.html
portmanteaux
<!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.
-->
<html>
@chalin
chalin / index.html
Last active September 28, 2019 11:36 — forked from Sfshaza/index.html
portmanteaux_simple
<!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.
-->
<html>
@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.
-->
@chalin
chalin / index.html
Last active May 18, 2021 05:57 — forked from Sfshaza/index.html
its_all_about_you
<!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.
-->
@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 / 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
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 {