Created
November 1, 2020 06:52
-
-
Save chimon2000/95b8e98274065c11f24e5c2c5bed28ae to your computer and use it in GitHub Desktop.
state_example: flutter command viewmodel
This file contains 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)); | |
inputChangedCommand.execute(''); | |
return state; | |
}, NotesState.initial()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment