Skip to content

Instantly share code, notes, and snippets.

View lukepighetti's full-sized avatar
🦞

Luke Pighetti lukepighetti

🦞
View GitHub Profile
@lukepighetti
lukepighetti / init_state.dart
Created June 7, 2020 15:54
Why does initState/dispose need to have a super call when they could be called by an internal method instead?
/// Alternative architecture for Flutter lifecycle methods.
///
/// Currently the framework uses @mustCallSuper to ensure that
/// important operations are called when lifecycle methods are
/// overridden. However, it is a common source of confusion for
/// developers about if the super should be called before or after
/// their own code.
///
/// This is a proposed alternative which has an internal `handleLifecycleMethod()`
/// method for each lifecycle event which calls `lifecycleMethod()` in the appropriate
@lukepighetti
lukepighetti / ffs_clipping.dart
Created June 20, 2020 16:33
Just another day fighting flutter
import 'package:flutter/material.dart';
import 'package:flutter_sandbox/widgets/layout/default_scaffold.dart';
import 'package:flutter_sandbox/themes/text_themes.dart';
class SandboxRoute extends StatefulWidget {
@override
_SandboxRouteState createState() => _SandboxRouteState();
}
class _SandboxRouteState extends State<SandboxRoute> {
@lukepighetti
lukepighetti / unused_dependencies.js
Created September 4, 2020 14:26
Search a Flutter project for unused dependencies
/// Finds unused dependencies from pubspec.yaml
///
/// Achieves this by parsing pubspec.yaml and recursively
/// searching the lib folder for an import statement that
/// contains the name of each package. Prints out the results.
const fs = require("fs");
const YAML = require("yaml");
const { execSync } = require("child_process");
/// Read pubspec.yaml
@lukepighetti
lukepighetti / table.dart
Last active September 9, 2020 18:23
Table formatting helper for console outputs https://twitter.com/luke_pighetti/status/1303736288315572224
import 'dart:math';
class Table {
/// Example output
///
/// ```
/// Range (yd) 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
/// Drop (in) -0.51, 0.06, 0.23, -0.03, -0.71, -1.84, -3.42, -5.46, -7.98, -10.99
/// Drop (moa) 4.78, -0.31, -0.73, 0.06, 1.35, 2.92, 4.65, 6.51, 8.45, 10.48
/// Windage (in) 0.03, 0.05, 0.09, 0.15, 0.22, 0.31, 0.41, 0.53, 0.66, 0.81
@lukepighetti
lukepighetti / text_editing_controller_builder.dart
Last active September 27, 2021 20:32
Wrap any TextField with TextEditingControllerBuilder to make it declarative
import 'package:flutter/widgets.dart';
class TextEditingControllerBuilder extends StatefulWidget {
/// Exposes a [TextEditingController] to the child, which allows
/// us to convert any [TextField] into a declarative version.
///
/// Typically used for wiring up many state fields to form inputs
/// and making sure everything stays in sync.
///
/// If [text] is updated, the consuming [TextField] will also be updated.
@lukepighetti
lukepighetti / geofencing-search-test.json
Last active January 1, 2021 21:14
https://github.com/synw/geojson/issues/33#issuecomment-753375534 ✓ Geofencing Search Extensions Loads GeoJSON file, gets bounding boxes, performs search
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lukepighetti
lukepighetti / moose_permit.dart
Last active January 9, 2021 23:48
A probability calculator for non-residents drawing moose permits in Maine https://dartpad.dev/6616482b100f6703c8ab96bbc4f169d7
import 'dart:math' show Random;
/// The chance of winning a non-resident moose
/// lottery with a single ticket.
final sides = 82;
/// The number of tickets purchased.
final rolls = 100;
/// The US Dollars required to buy a ticket.
@lukepighetti
lukepighetti / theme_brightness_animated_builder.dart
Last active January 30, 2021 23:16
A simple way to handle light/dark theme with animation tied to ThemeData.
import 'package:flutter/material.dart';
/// ```dart
/// class MyLightAndDarkThemeWidget extends StatelessWidget {
/// @override
/// Widget build(BuildContext context) {
/// return ThemeBrightnessAnimatedBuilder(
/// builder: (context, t, child) {
/// final lightThemeColor = Colors.red.shade800;
/// final darkThemeColor = Colors.red.shade200;
@lukepighetti
lukepighetti / main.dart
Last active February 14, 2021 18:13
Can't seem to map a stream with async* for some reason
void main() async {
final test = TestClass();
print(await test.mapIsOdd.first);
print(await test.asyncStarIsOdd.first);
}
Stream<int> get stream => Stream.fromIterable([1, 2, 3, 4, 5, 6]);
class TestClass {
import 'package:flutter/material.dart';
import '../extensions/extensions.dart';
typedef AnimatedGridBuilder<T> = Widget Function(
BuildContext, T item, AnimatedGridDetails details);
class AnimatedGrid<T> extends StatelessWidget {
/// An animated grid the animates when the items change sort.
const AnimatedGrid({