Skip to content

Instantly share code, notes, and snippets.

@krisgiesing
krisgiesing / disk_asset_bundle.dart
Last active November 20, 2019 18:21
Golden screenshot test with file image
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:glob/glob.dart';
/// A simple implementation of [AssetBundle] that reads files from an asset dir.
///
@krisgiesing
krisgiesing / gist:e00a53afc48e7e6417f0b04b78004ddb
Last active November 12, 2019 12:54
Desired API properties for actions
/// Client (application-specific) code
// Presents an affordance for inspecting the current state of
// a given action, and for triggering that action if possible
class ActionStatePresenter extends StatelessWidget {
ActionStatePresenter({this.actionKey});
Intent actionKey;
@override
Widget build(BuildContext context) {
// Here we set up a dependency relationship with the ActionManager
@krisgiesing
krisgiesing / key_test.dart
Last active October 22, 2019 06:48
Small test file to illustrate how seemingly legal code can produce a duplicate key exception in Flutter.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
group('KeyTest', () {
const double itemHeight = 48.0;
final List<String> listItems = <String>['Item 1', 'Item 2', 'Item 3', 'Item 4'];
final List<GlobalKey> indexedKeys = <GlobalKey>[
GlobalKey(debugLabel: '0'),
---------------
Building drag target (1, 2)
Building ghost index: [<'Item 3'>]
Building drag target (1, 1)
Building current index (1): [<'Item 2'>]
Building main scroll view
Wrapping [<'Item 1'>] at 0
Wrapping [<'Item 2'>] at 1
Wrapping [<'Item 3'>] at 2
Wrapping [<'Item 4'>] at 3
@krisgiesing
krisgiesing / gist:5f61d7f034aed4d9329ff3f3232cb6ca
Created October 7, 2019 22:02
Exception thrown during ReorderableListView demo
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building Listener:
flutter: Multiple widgets used the same GlobalKey [_ScopedValueGlobalKey<_ReorderableListContentState>
flutter: _ReorderableListContentState#7057b [<'F'>]].
flutter: The key [_ScopedValueGlobalKey<_ReorderableListContentState> _ReorderableListContentState#7057b
flutter: [<'F'>]] was used by multiple widgets. The parents of those widgets were:
flutter: - _PointerListener(listeners: [down], behavior: deferToChild, renderObject:
flutter: RenderPointerListener#45bbd relayoutBoundary=up5 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE)
flutter: - _PointerListener(listeners: [down], behavior: deferToChild, renderObject:
flutter: RenderPointerListener#5fbfc relayoutBoundary=up4)
@krisgiesing
krisgiesing / circular_deps.dart
Created July 1, 2019 19:19
Dart value comparable type problem
class Bar {
Bar({this.foo});
Foo foo;
String toString() => 'bar:$foo';
}
class Foo {
Foo({this.bar});
Bar bar;
String toString() => 'foo:$bar';
@krisgiesing
krisgiesing / gist:64a85385cb8dd836f577
Created December 16, 2015 01:36
BoxDecoration issue
Widget build(BuildContext context) {
return new Scaffold(
toolBar: new ToolBar(
center: new Text("Flutter Demo")
),
body: new DecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0x774444)),
child: new Center(child: new Text("Hello World"))
)
);
import 'dart:sky' as sky; // Defines sky.Event and sky.EventCallback
class Event {}
// With this typedef, the code fails at runtime with:
// type '(Event) => void' is not a subtype of type 'EventCallback' of 'callback'.
// Removing this typedef causes the code to succeed
typedef void FooBar(Event event);
void main() {