Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan chimon2000

View GitHub Profile
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 / main.dart
Last active Nov 3, 2020
state_example: app widget
View main.dart
void main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ProviderScope(
child: MaterialApp(
title: 'Flutter Demo',
@chimon2000
chimon2000 / main.dart
Last active Nov 3, 2020
state_example: bloc main
View main.dart
void main() {
// For widgets to be able to read providers, we need to wrap the entire
// application in a "BlocProvider" widget.
// This is where the state of our NotesCubit will be stored.
runApp(BlocProvider<NotesCubit>(create: (_) => NotesCubit(), child: App()));
}
@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;
@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 / 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 / main.dart
Last active Nov 3, 2020
state_example: binder root
View main.dart
void main() {
// For widgets to be able to read app state, we need to wrap the entire
// application in a "BinderScope" widget.
runApp(BinderScope(child: App()));
}
@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 / notes.dart
Created Nov 1, 2020
state_example: mobx note store
View notes.dart
part 'notes.g.dart';
class Notes = NotesBase with _$Notes;
abstract class NotesBase with Store {
@observable
String input = '';
@observable
ObservableList<String> notes = ObservableList();
@chimon2000
chimon2000 / notes.viewmodel.dart
Created Nov 1, 2020
state_example: flutter command viewmodel
View notes.viewmodel.dart
class NotesViewModel {
NotesState state = NotesState.initial();
Command<String, String> inputChangedCommand;
Command<String, NotesState> updateNotesCommand;
NotesViewModel() {
inputChangedCommand = Command.createSync((x) => x, '');
updateNotesCommand = Command.createSync((input) {
state = state.copyWith(notes: state.notes.concat(input));