Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan chimon2000

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am chimon2000 on github.
  • I am chimon (https://keybase.io/chimon) on keybase.
  • I have a public key ASBC8JzAWtEGVqem8e2M5UfYTFCO2XaY42p0bce6fCtpdgo

To claim this, I am signing this object:

@chimon2000
chimon2000 / cloudSettings
Last active Mar 5, 2020
Provider Widget Rebuild
View cloudSettings
{"lastUpload":"2020-03-05T07:06:07.448Z","extensionVersion":"v3.4.3"}
View main.dart
import 'package:flutter/material.dart';
void main() => runApp(
Center(
child: Text(
'Hello Charlotte Devs!',
textDirection: TextDirection.ltr,
),
),
);
@chimon2000
chimon2000 / reducer_notifier.dart
Last active Apr 14, 2020
Reducer with State Notifier
View reducer_notifier.dart
import 'dart:async';
import 'package:state_notifier/state_notifier.dart';
class ReducerNotifier<State> extends StateNotifier<State> {
final Reducer<State> reducer;
ReducerNotifier(state, this.reducer) : super(state);
FutureOr<void> dispatch(Action action) async {
@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]);
View counter_page.dart
class CounterPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Counter')),
body: BlocBuilder<CounterCubit, int>(
builder: (context, count) => Center(child: Text('$count')),
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
View counter_bloc.dart
enum CounterEvent { increment }
class CounterBloc extends Bloc<CounterEvent, int> {
CounterBloc() : super(0);
@override
Stream<int> mapEventToState(CounterEvent event) async* {
switch (event) {
case CounterEvent.increment:
yield state + 1;
View counter_cubit.dart
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
}
@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;
}
@chimon2000
chimon2000 / base_command.dart
Created Oct 22, 2020
Command Pattern in Dart (Cubit + GetIt)
View base_command.dart
import 'package:get_it/get_it.dart';
abstract class BaseCommand<T> {
GetIt getIt = GetIt.instance;
D locate<D>() => getIt.get<D>();
Future<T> run();
}