Skip to content

Instantly share code, notes, and snippets.

View josh-burton's full-sized avatar
👋

Josh Burton josh-burton

👋
View GitHub Profile
@josh-burton
josh-burton / SharedPreferencesObservable.kt
Created February 1, 2018 18:50
A kotlin extension to allow shared preference values to be observed
inline fun <reified T> SharedPreferences.observe(keyToObserve: String, defaultValue: T): Observable<T> {
return Observable.create<T> { emitter ->
val listener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == keyToObserve) {
val value = sharedPreferences.all[key]
if (value is T) {
emitter.onNext(value)
} else {
Timber.w("SharedPreferences", "Warning: observed preference type does not match")
@josh-burton
josh-burton / installflutter.sh
Last active March 3, 2018 20:28
install flutter on bitrise
#!/usr/bin/env bash
# fail if any commands fails
set -e
# debug log
set -x
cd ..
git clone -b dev https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH
envman add --key PATH --value $PATH
allProjects {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += [
"-Adagger.formatGeneratedSource=disabled",
"-Adagger.gradle.incremental=true"
]
}
afterEvaluate {
@josh-burton
josh-burton / main.dart
Created April 7, 2021 20:19
split view overflow box
// 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';
import 'dart:math';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@josh-burton
josh-burton / json
Created November 22, 2021 21:24
allOf dart-dio-next bug
{
"openapi": "3.0.0",
"info": {
"title": "TestApi",
"version": "1.0"
},
"paths": {
"/users/{userId}": {
"parameters": [
{
@josh-burton
josh-burton / main.dart
Last active August 15, 2022 19:56
Riverpod StateProvider select vs watch
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
void main() {
runApp(
const ProviderScope(child: MyApp()),
);
}
final sourceProvider = StateProvider((ref) => 0);