Skip to content

Instantly share code, notes, and snippets.

View justinmc's full-sized avatar

Justin McCandless justinmc

View GitHub Profile
@justinmc
justinmc / main.dart
Last active August 22, 2022 20:33
Example of using Shortcuts and Actions together
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@justinmc
justinmc / main.dart
Last active August 24, 2022 16:53
Example of the most basic usage of the Actions widget. Starting point: https://gist.github.com/justinmc/431278869ca70372f00e469121055aaa
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
@justinmc
justinmc / main.dart
Created August 17, 2022 17:20
An example of getting all field values in a Form.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
@justinmc
justinmc / main.dart
Created August 16, 2022 17:11
Example of a GestureDetector inside InteractiveViewer
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
@justinmc
justinmc / main.dart
Last active July 21, 2022 20:33
An option for SpellCheckConfiguration default values in TextField: styleGetter function
import 'package:flutter/foundation.dart';
void main() {
const FakeTextField notPassed = FakeTextField();
const FakeTextField passedNull = FakeTextField(spellCheckConfiguration: null);
const FakeTextField passed = FakeTextField(
spellCheckConfiguration: SpellCheckConfiguration(
service: 'myservice',
handler: 'myhandler',
styleGetter: FakeTextField.defaultStyleGetter,
@justinmc
justinmc / main.dart
Created July 13, 2022 23:22
An example of a compound FormField that contains multiple sub-FormFields. See also: https://gist.github.com/justinmc/120893372689ce66bbf89e5178848834
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({
super.key,
});
@override
@justinmc
justinmc / main.dart
Created July 12, 2022 18:08
Example of distinguishing between null and not-passed function parameter to class
void main() {
final Foo defaultFoo = Foo();
defaultFoo.talk();
final Foo namedFoo = Foo(name: 'Justin', nameGetter: () => 'Justin');
namedFoo.talk();
final Foo nullFoo = Foo(name: null, nameGetter: null);
nullFoo.talk();
}
@justinmc
justinmc / main.dart
Last active May 20, 2022 22:52
Exploring abstract class vs. mixin for breaking changes
void main() {
final Abstract implementer = Implementer();
implementer.foo();
final Abstract extender = Extender();
extender.foo();
final Mixin mixer = MixerWith();
mixer.bark();
}
@justinmc
justinmc / main.dart
Created May 2, 2022 21:45
Pan gesture localPosition bug?
// Copyright (c) 2019, 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.
// 1. Open the console so you can see the prints.
// 2. Scroll to the bottom of the red/blue container and tap.
// The location of the tap is logged.
// Notice that the local dy includes the scrolling and global does not.
// 3. Scroll back up to the top and start dragging.
// The location of the drag is continuously logged.
@justinmc
justinmc / main.dart
Last active July 13, 2022 23:22
An example of looking up a Form's invalid field, updated for NNBD. See also https://gist.github.com/justinmc/10516ec33b8223b0e7c2a14432aa161b
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,