Skip to content

Instantly share code, notes, and snippets.

void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Title')),
body: Text('Hello World'),
floatingActionButton: FloatingActionButton(
onPressed: () => print('Button pressed'),
child: Icon(Icons.add),
),
@kasperpeulen
kasperpeulen / gist2.dart
Created November 26, 2021 09:45
Providing context
import 'package:flutter/widgets.dart';
void main() {
runApp(
Directionality(
textDirection: TextDirection.ltr,
child: Text('Hello World!'),
),
);
}
@kasperpeulen
kasperpeulen / flutter1.dart
Last active November 26, 2021 09:38
Hello World
import 'package:flutter/widgets.dart';
void main() {
runApp(Text('Hello World!'));
}
import 'dart:async';
// non-nullable state
final todos = StateStream(state: <Todo>[]);
final counter = StateStream(state: 0);
// nullable state
final selectedTodo = StateStream<Todo?>(state: null);
void main() {
import 'dart:async';
// non-nullable state
final todos = StateStream(state: <Todo>[]);
final counter = StateStream(state: 0);
// nullable state
final selectedTodo = StateStream<Todo?>();
void main() {
type Monad<A> = Array<A>;
function of<A>(a: A): Monad<A> {
return [a];
}
function flatMap<A, B>(monad: Monad<A>, callback: (a: A) => Monad<B>): Monad<B> {
return monad.flatMap(callback);
}
Promise.resolve(3).then(x => /* x is 3 here */)
const x = await Promise.resolve(3) // x is 3 here as well
const x = await Promise.resolve(Promise.resolve(3))
// x is 3 here
// but should be Promise.resolve(3)
const promise2 = promise1.then(x => Promise.resolve(x))
// promise1 and promise2 are equivalent
const promise2 = Promise.resolve(await promise1)
// promise1 and promise2 are equivalent
const a = yield* pick([1, 2]);
// a is inferred as type number
const b = yield* pick(['Foo', 'Bar'] as const);
// b is inferred as type 'Foo' | 'Bar'