Skip to content

Instantly share code, notes, and snippets.

@chimon2000
Created November 1, 2020 06:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chimon2000/95b8e98274065c11f24e5c2c5bed28ae to your computer and use it in GitHub Desktop.
state_example: flutter command viewmodel
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