This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // We create a "state ref", which will store a reference to NotesState. | |
| final notesRef = StateRef(NotesState.initial()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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())); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| part 'notes.g.dart'; | |
| class Notes = NotesBase with _$Notes; | |
| abstract class NotesBase with Store { | |
| @observable | |
| String input = ''; | |
| @observable | |
| ObservableList<String> notes = ObservableList(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BlocPage extends StatefulWidget { | |
| const BlocPage({Key key}) : super(key: key); | |
| @override | |
| _BlocPageState createState() => _BlocPageState(); | |
| } | |
| class _BlocPageState extends State<BlocPage> { | |
| TextEditingController _controller; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NotesCubit extends Cubit<NotesState> { | |
| NotesCubit(): super(NotesState.initial()); | |
| void addNote() { | |
| emit(state.copyWith(notes: state.notes.concat(state.input), input: '')); | |
| } | |
| void updateInput(String input) => emit(state.copyWith(input: input)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RiverpodPage extends StatefulWidget { | |
| const RiverpodPage({Key key}) : super(key: key); | |
| @override | |
| _RiverpodPageState createState() => _RiverpodPageState(); | |
| } | |
| class _RiverpodPageState extends State<RiverpodPage> { | |
| TextEditingController _controller; |