Skip to content

Instantly share code, notes, and snippets.

View ThinkDigitalSoftware's full-sized avatar
💭
An app a day keeps the doctor away

Jonathan White ThinkDigitalSoftware

💭
An app a day keeps the doctor away
  • ThinkDigitalSoftware
  • California, United States of America
View GitHub Profile
void main() {
final map = {'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]};
var listOfItems = [1, 2, 3, 4, 5, 6, 7 ,8, 9]..shuffle();
final mappedItems = {};
int iterations = 0;
for(final key in map.keys){
void main() {
print(SuperClass.create(true).runtimeType);
print(SuperClass.create(false).runtimeType);
}
class SuperClass {
SuperClass();
factory SuperClass.create(bool createSubclass1) {
if (createSubclass1) {
return Subclass1();
@ThinkDigitalSoftware
ThinkDigitalSoftware / main.dart
Created July 7, 2020 21:32
/// Future timeout example
/// Future timeout example
void main() async {
final howLongItTakesToDownloadTheInternet = Duration(days: 365);
final youAreAnImpatientDeveloper = true;
Future downloadTheInternet() =>
Future.delayed(howLongItTakesToDownloadTheInternet);
if (youAreAnImpatientDeveloper) {
// you can use timeout on any future and it'll throw an error if a future doesn't
// complete before you run out of patience.
void main() {
var s1 = S();
print(s1?.num ?? 0 > 1);
var s2 = S()..num = 1.0;
print(s2?.num ?? 0 > 1);
}
class S {
double num;
}
@ThinkDigitalSoftware
ThinkDigitalSoftware / fallback_loading_cached_network_image.dart
Last active April 27, 2020 01:47
A Flutter widget that will loop through urls until it finds a valid imageurl or builds the error widget
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
class FallbackLoadingCachedNetworkImage extends StatelessWidget {
final List<String> urls;
final LoadingErrorWidgetBuilder errorWidget;
const FallbackLoadingCachedNetworkImage({
Key key,
@required this.urls,
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:fritter_for_reddit/exports.dart';
import 'package:hive/hive.dart';
/// Every time notifyListeners is called, the state is persisted to allow easy app persistence.
/// Persistence is based on Hive with a box opened with the class name.
/// If this is not desired, supply an alternative [boxName] in the constructor.
@ThinkDigitalSoftware
ThinkDigitalSoftware / main.dart
Created April 6, 2020 20:21
Completer example
import 'dart:async';
final Completer<int> halfwayPointCompleter = Completer();
void main() async {
print('getting started');
calculateSomeNumbers(10).then((result) => print(result)); // async
int halfwayPoint = await halfwayPointCompleter.future;
print(halfwayPoint);
// this will print before the above function completes because it's waiting for the //halfwayPointCompleter to complete, which completes halfway through
@ThinkDigitalSoftware
ThinkDigitalSoftware / conversions.md
Created March 12, 2020 19:27
Flutter 1.13.8 to 1.14+ conversions

The names of the TextTheme properties match this table from the /// Material Design spec /// with two exceptions: the styles called H1-H6 in the spec are /// headline1-headline6 in the API, and body1,body2 are called /// bodyText1 and bodyText2.

NAME SIZE WEIGHT SPACING 2018 NAME /// display4 112.0 thin 0.0 headline1 /// display3 56.0 normal 0.0 headline2 /// display2 45.0 normal 0.0 headline3

@ThinkDigitalSoftware
ThinkDigitalSoftware / bloc_globals.dart
Last active March 11, 2020 19:44
Adds a simple Bloc delegate that prints events and their calling function.
// don't forget to add `BlocSupervisor.delegate = SimpleBlocDelegate();` to the beginning of your main.dart file.
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class SimpleBlocDelegate extends BlocDelegate {
SimpleBlocDelegate() {
debugPrint(
'[INFO] Initializing SimpleBlocDelegate. Logging all Bloc events to the console');
@ThinkDigitalSoftware
ThinkDigitalSoftware / main.dart
Created March 11, 2020 00:08
AnimatedList example
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override