Skip to content

Instantly share code, notes, and snippets.

@wyattbiker
wyattbiker / main.dart
Created May 12, 2019 01:46
Stream example
// asynchronous data
main() async {
// Duration interval = Duration(seconds: 1);
// Stream<int> stream = Stream<int>.periodic(interval, callback);
// List l=[1,2,1,2,3,4,5,6];
// Stream stream = Stream.fromIterable(l);
Map<dynamic, int> map = {1: 1, 'a': 10, 'b': 20, 3: 2, 4: 4, 6: 5};
Stream stream = Stream.fromIterable(map.entries);
@wyattbiker
wyattbiker / main.dart
Last active May 11, 2019 11:12
Bye class
class Bye {
int a = 1;
}
class Say extends Bye {
int a = 2;
}
void printBye<T extends Say>(T b) {
print(b); // prints Instance of Bye
@wyattbiker
wyattbiker / main.dart
Created May 8, 2019 16:08
futures examples
// 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';
import 'dart:io';
Future<void> printDailyNewsDigest() async {
var newsDigest = await gatherNewsReports();
print(newsDigest);
@wyattbiker
wyattbiker / main.dart
Created May 8, 2019 15:02
yield examples
import 'dart:math' as m;
class Animal {
void chase(Animal x) {
print("Animal $x");
}
}
class Mouse extends Animal {}
import 'dart:io';
class Logxy {
static String sName;
static num slog;
static Logxy _logger;
// Logxy._() : super._();
// Logxy._(this.sName);
@wyattbiker
wyattbiker / main.dart
Created May 7, 2019 01:20
Get random filename
import 'dart:math';
void main() {
print(getRandFilename(8));
}
String getRandFilename(int fileNameLength) {
Random r = Random();
int randF = pow(10, fileNameLength);
randF = r.nextInt(randF);
@wyattbiker
wyattbiker / main.dart
Last active May 3, 2019 21:13
Generics example
// T is meant to be a Type
// E is meant to be an Element (List<E>: a list of Elements)
// K is Key (in a Map<K, V>)
// V is Value (as a return value or mapped value)
class CacheItem<T, V> {
T itemToCache;
V amountToCache;
CacheItem(T this.itemToCache, V this.amountToCache);
T get detail => itemToCache;
@wyattbiker
wyattbiker / main.dart
Last active May 3, 2019 15:04
Example of dartpad code
import 'dart:io';
var x = 4;
class xyz {}
void arrexpr(num n) => (print(n));
void main() {
// print(Platform.pathSeparator);