Skip to content

Instantly share code, notes, and snippets.

View lukepighetti's full-sized avatar
🦞

Luke Pighetti lukepighetti

🦞
View GitHub Profile
@lukepighetti
lukepighetti / value_observable_builder.dart
Last active October 14, 2019 23:54
Value observable builder
import 'package:rxdart/rxdart.dart';
import 'package:flutter/widgets.dart';
/// A more traditional StreamBuilder style builder method
class ValueObservableBuilder<T> extends StreamBuilder<T> {
ValueObservableBuilder({
Key key,
ValueObservable<T> valueObservable,
AsyncWidgetBuilder<T> builder,
}) : super(key: key, stream: valueObservable, initialData: valueObservable.value, builder: builder);
@lukepighetti
lukepighetti / extensions.dart
Created February 12, 2020 18:35
Quick example of what an extensions file might look like in one of my projects
import 'package:email_validator/email_validator.dart';
import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as material;
import 'package:intl/intl.dart';
import 'package:rxdart/rxdart.dart';
extension BuildContextExtensions on BuildContext {
dynamic get arguments => ModalRoute.of(this).settings.arguments;
@lukepighetti
lukepighetti / styles.dart
Last active March 4, 2020 01:58
Extensions to get a project started
import 'package:flutter/material.dart';
class AppStyle {
static double get paddingUnit => 16;
static TextStyle get text28 => TextStyle(fontSize: 28).withTightSpacing;
static TextStyle get text20 => TextStyle(fontSize: 20).withTightSpacing;
static TextStyle get text16 => TextStyle(fontSize: 16).withNormalSpacing;
static TextStyle get text14 => TextStyle(fontSize: 14).withNormalSpacing;
static TextStyle get text12 => TextStyle(fontSize: 12).withWideSpacing;
@lukepighetti
lukepighetti / blockchain.dart
Created March 5, 2020 19:37
A dead simple blockchain written in Dart in 93 lines
import 'dart:collection';
import 'dart:convert' as convert;
import 'package:crypto/crypto.dart' as crypto;
import 'package:flutter_test/flutter_test.dart';
main() {
testWidgets('Create, add, pass validate, tamper, fail validation', (_) async {
final blockchain = Blockchain();
expect(blockchain.isValid, isTrue);
@lukepighetti
lukepighetti / loading_notification_listener_route.dart
Last active March 8, 2020 01:31
A declarative™ way to handle loading notifications with Widgets™
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:material_theme/loading_notification/loading_image.dart';
import 'package:material_theme/loading_notification/loading_notification_listener.dart';
import 'package:material_theme/widgets/layout/default_scaffold.dart';
import 'loading_future_builder.dart';
class LoadingNotificationsRoute extends StatefulWidget {
@lukepighetti
lukepighetti / main.dart
Last active March 16, 2020 19:33
Extensions don't fuck anything up
// 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.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@lukepighetti
lukepighetti / client.dart
Last active September 7, 2021 20:54
Logging service using extensions for channels with multiple outputs
import 'package:logger/logger.dart';
void main() async {
/// Setup logging service
final remoteUrl = Uri.parse('http://localhost:8080');
final logger = LoggingService(
loggers: {
ConsoleLogger(),
RemoteLogger(baseUrl: remoteUrl),
},
@lukepighetti
lukepighetti / freezed_model.json
Created April 28, 2020 22:10
VSCode snippets
{
"Freezed model": {
"prefix": "frz",
"body": [
"import 'package:freezed_annotation/freezed_annotation.dart';",
"",
"part '$TM_FILENAME_BASE.freezed.dart';",
"",
"@freezed",
"abstract class ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/g}} with _$${1} {",
@lukepighetti
lukepighetti / main.dart
Created May 15, 2020 01:40
Async constructor arguments, sequential or parallel?
main() async {
print("Start");
var s = Stopwatch()..start();
/// It would be nice if getFoo() and getBar() were evaluated in parallel,
/// as if they were performed with Future.wait()
final result = Foo(await getFoo(), await getBar());
print("Stop: ${s.elapsed}");
}
@lukepighetti
lukepighetti / implicitly_animated_builder.dart
Created May 17, 2020 20:08
ImplicitlyAnimatedBuilder
import 'package:flutter/material.dart';
/// An implicitly animated builder that tweens from 0.0 to 1.0 based on `isActive` property
class ImplicitlyAnimatedBuilder extends ImplicitlyAnimatedWidget {
ImplicitlyAnimatedBuilder({
Key key,
@required Curve curve,
@required Duration duration,
@required this.isActive,
@required this.builder,