Skip to content

Instantly share code, notes, and snippets.

@chimon2000
Last active November 3, 2020 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chimon2000/62a84c981508a7a01d8716f7eb41ff79 to your computer and use it in GitHub Desktop.
Save chimon2000/62a84c981508a7a01d8716f7eb41ff79 to your computer and use it in GitHub Desktop.
state_example: notes viewlogic
// 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() {
var state = read(notesRef);
write(notesRef,
state.copyWith(notes: state.notes.concat(state.input), input: ''));
}
void updateInput(String input) =>
write(notesRef, read(notesRef).copyWith(input: input));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment