Skip to content

Instantly share code, notes, and snippets.

Avatar
🦞
Back at the home office

Luke Pighetti lukepighetti

🦞
Back at the home office
View GitHub Profile
@lukepighetti
lukepighetti / Makefile
Last active May 31, 2021
Basic Flutter Makefile
View Makefile
VERSION = 1.0.0
BUILD = 8
CHANGELOG = Added item counts and a celebration when a list is completed.
.PHONY: clean test build distribute
clean:
flutter clean
flutter pub get
pod repo update
View control_flow_collections.dart
/// An example of operations you can do with control flow collections.
///
/// They make it very easy to do map, filter, and spread operations, all
/// while retaining the base class of [List<T>], [Set<T>], and [Map<K,V>]
void main() {
final source = [1, 2, 3, null, 4, 5, null];
/// List control flow, map & filter
final myList = [
for (var number in source)
@lukepighetti
lukepighetti / main.dart
Created Apr 12, 2021
Using flutter_portal to create a popover that allows the base view to remain interactive
View main.dart
import 'package:flutter/material.dart';
import 'package:flutter_portal/flutter_portal.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
static const title = 'Spike Overlay TextField';
@lukepighetti
lukepighetti / json_encode.dart
Last active Apr 11, 2021
Testing jsonEncode with a class that has a toJson method.
View json_encode.dart
import 'dart:convert';
void main() {
final foo = Foo('bar');
print(foo);
print(foo.foo);
print(jsonEncode(foo));
print(jsonEncode([foo, foo, foo]));
}
@lukepighetti
lukepighetti / example.dart
Last active Mar 27, 2021
Simple route generator that exposes arguments and query params to route builders
View example.dart
main() {
BuildContext context;
final router = NavigationService(context);
return MaterialApp(
onGenerateRoute: (settings) => router.handleGenerateRoute(
settings,
routes: {
'/': (params, context) => HomeView(),
@lukepighetti
lukepighetti / database.dart
Last active Mar 25, 2021
A dead simple JSON based key/value store that is unbelievably useful for scripts and tools
View database.dart
import 'dart:convert';
import 'dart:io';
class Database {
/// A simple JSON file database
Database(String path) : file = File(path);
final File file;
var _store = <String, dynamic>{};
@lukepighetti
lukepighetti / dart.yml
Last active Mar 13, 2021
Flutter Web + GitHub Actions + Firebase Hosting Preview Channels
View dart.yml
# .github/workflows/dart.yml
name: build
on:
push:
branches: [master]
pull_request:
branches: [master]
View animated_grid.dart
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({
@lukepighetti
lukepighetti / main.dart
Last active Feb 14, 2021
Can't seem to map a stream with async* for some reason
View main.dart
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 {
@lukepighetti
lukepighetti / theme_brightness_animated_builder.dart
Last active Jan 30, 2021
A simple way to handle light/dark theme with animation tied to ThemeData.
View theme_brightness_animated_builder.dart
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;