Skip to content

Instantly share code, notes, and snippets.

View bsutton's full-sized avatar

Brett Sutton bsutton

  • @mention onepub
  • Melbourne, Australia
  • 19:25 (UTC +11:00)
View GitHub Profile
import 'package:flutter/material.dart';
class GrayedOut extends StatelessWidget {
final Widget child;
final bool grayedOut;
GrayedOut({@required this.child, this.grayedOut = true});
@override
@bsutton
bsutton / grayed_out.dart
Last active October 17, 2019 05:26
Updated grayed_out
import 'package:flutter/material.dart';
class GrayedOut extends StatelessWidget {
final Widget child;
final bool grayedOut;
final double opacity;
GrayedOut({@required this.child, this.grayedOut = true})
: opacity = grayedOut == true ? 0.3 : 1.0;
@bsutton
bsutton / Alignment.dart
Created October 16, 2019 07:06
Left and Right alignment widgets for Flutter
import 'package:flutter/material.dart';
class Left extends StatelessWidget {
final Widget child;
Left({@required this.child});
@override
Widget build(BuildContext context) {
return Align(alignment: Alignment.centerLeft, child: child);
@bsutton
bsutton / main.dart
Last active October 31, 2019 21:58
Future sort
void main() {
List<Future<Option>> options = [Future.value(Option(2)), Future.value(Option(3)), Future.value(Option(1))];
options.sort((lhs, rhs) => lhs.ordinal - rhs.ordinal);
}
class Option
{
void main() async {
// pretend I've just return the set of options from an REST call to the db
List<RefOption> refs = [RefOption(2), RefOption(3), RefOption(1)];
await resolveList(refs);
refs.sort((lhs, rhs) => lhs.option.ordinal - rhs.option.ordinal);
for (RefOption ref in refs)
class IdRef<E extends Entity> {
GUID guid;
// Once the entity has been resolved we cache it here.
E resolvedEntity;
/// Creates an IdRef from a guid.
///
/// Calling [future] will trigger the process
/// to resolve the entity (i.e. do the network call)
@bsutton
bsutton / gist:acbda315533917a1eb76dcfd02947d5e
Created November 8, 2019 06:27
Dart: Overloading generic method
class MyRepo
{
}
class RealRepo<E extends Entity>
{
Repository<E> repo;
}
abstract class TypedEvent<T>
@bsutton
bsutton / main.dart
Created December 4, 2019 23:38
StackTraceImpl
import "dart:core" as core show StackTrace;
import "dart:core";
import 'dart:io';
import 'package:path/path.dart';
class StackTraceImpl implements core.StackTrace {
static final stackTraceRegex = RegExp(r'#[0-9]+[\s]+(.+) \(([^\s]+)\)');
final core.StackTrace stackTrace;
@bsutton
bsutton / hello_world.dart
Created January 13, 2020 07:31
Hello world
#! /usr/bin/env dshell
import 'package:dshell/dshell.dart';
void main() {
print('Hello World');
}
@bsutton
bsutton / dshell_install.sh
Created January 13, 2020 07:39
install dshell
chmod +x hello_world.dart
./hello_world.dart