Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan chimon2000

View GitHub Profile
@chimon2000
chimon2000 / base.command.dart
Last active Jul 30, 2021
Command Pattern in Dart
View base.command.dart
abstract class BaseCommand<T> {
BuildContext _context;
BaseCommand(BuildContext context) {
/// Get root context
/// If we're passed a context that is known to be root, skip the lookup, it will throw an error otherwise.
_context = (context == _lastKnownRoot) ? context : context.read();
_lastKnownRoot = _context;
}
View get_it_web_bug.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
Future<void> main() async {
await initApp();
runApp(MyApp());
}
@chimon2000
chimon2000 / use_state_notifier.dart
Created May 5, 2020
Flutter Hook for StateNotifier
View use_state_notifier.dart
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:state_notifier/state_notifier.dart';
T useStateNotifier<T>(StateNotifier<T> notifier) {
final state = useState<T>(null);
useEffect(() {
return notifier.addListener((s) => state.value = s);
}, [notifier]);
@chimon2000
chimon2000 / mobx.page.dart
Last active Nov 3, 2020
state_example: mobx page
View mobx.page.dart
class MobxPage extends StatefulWidget {
const MobxPage({Key key}) : super(key: key);
@override
_MobxPageState createState() => _MobxPageState();
}
class _MobxPageState extends State<MobxPage> {
var _notesStore = Notes();
TextEditingController _controller;
@chimon2000
chimon2000 / flutter_command.page.dart
Last active Nov 3, 2020
state_examples: flutter command page
View flutter_command.page.dart
class FlutterCommandPage extends StatefulWidget {
const FlutterCommandPage({Key key}) : super(key: key);
@override
_FlutterCommandPageState createState() => _FlutterCommandPageState();
}
class _FlutterCommandPageState extends State<FlutterCommandPage> {
final _notesViewModel = NotesViewModel();
TextEditingController _controller;
@chimon2000
chimon2000 / bloc.page.dart
Last active Nov 3, 2020
state_examples bloc page
View bloc.page.dart
class BlocPage extends StatefulWidget {
const BlocPage({Key key}) : super(key: key);
@override
_BlocPageState createState() => _BlocPageState();
}
class _BlocPageState extends State<BlocPage> {
TextEditingController _controller;
@chimon2000
chimon2000 / notes.dart
Last active Nov 3, 2020
state_example: binder notes
View notes.dart
// We create a "state ref", which will store a reference to NotesState.
final notesRef = StateRef(NotesState.initial());
@chimon2000
chimon2000 / notes.viewlogic.dart
Last active Nov 3, 2020
state_example: notes viewlogic
View notes.viewlogic.dart
// We create a "logic ref", which will store a reference to NotesViewLogic.
final notesViewLogicRef = LogicRef((scope) => NotesViewLogic(scope));
class NotesViewLogic with Logic {
const NotesViewLogic(this.scope);
@override
final Scope scope;
void addNote() {
@chimon2000
chimon2000 / binder.page.dart
Last active Nov 3, 2020
state_example: binder page
View binder.page.dart
class BinderPage extends StatefulWidget {
const BinderPage({Key key}) : super(key: key);
@override
_BinderPageState createState() => _BinderPageState();
}
class _BinderPageState extends State<BinderPage> {
TextEditingController _controller;
View riverpod.page.dart
class RiverpodPage extends StatefulWidget {
const RiverpodPage({Key key}) : super(key: key);
@override
_RiverpodPageState createState() => _RiverpodPageState();
}
class _RiverpodPageState extends State<RiverpodPage> {
TextEditingController _controller;