Skip to content

Instantly share code, notes, and snippets.

View HosseinYousefi's full-sized avatar
🦀

Hossein Yousefi HosseinYousefi

🦀
View GitHub Profile
extension type Intersection<T, U>._(dynamic _value) {
factory Intersection(dynamic value) {
if (value is! T && value is! U) {
throw StateError('Invalid type');
}
return Intersection(value);
}
}
import 'dart:async';
class MyStreamController {
final MyStream stream;
MyStreamController() : stream = MyStream();
void add(int i) {
Future.microtask(() {
stream.lastElement = i;
class A {
static int g() {
print('happens');
return 42;
}
static final int f = g();
}
void main() {
print('hmm?');
import random
total = 0
boys = 0
for _ in range(10000):
population = [(random.choice(['B', 'G']), random.choice(['B', 'G'])) for _ in range(1000)]
mr_smith_kids = random.choice(population)
if mr_smith_kids == ('G', 'G'): # We know this did not happen
continue
total += 1
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Builder(
builder: (context) {
String _value = 'D'; // is not in your hand
mixin B on Z {
String get value => _value;
String get cachedValue;
@override
void call() {
print('in B: $value, $cachedValue');
super.call();
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(home: A()));
}
class A extends StatefulWidget {
@override
_AState createState() => _AState();
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
import 'dart:async';
Future<void> wait(int millis) =>
Future.delayed(Duration(milliseconds: millis));
Stream<String> userTyping() async* {
await wait(100);
yield 'h';
await wait(100);
yield 'he';