Skip to content

Instantly share code, notes, and snippets.

@xinthink
Created March 5, 2020 09:53
Show Gist options
  • Save xinthink/bfb348de0e95da409d4622d9f0cd5c18 to your computer and use it in GitHub Desktop.
Save xinthink/bfb348de0e95da409d4622d9f0cd5c18 to your computer and use it in GitHub Desktop.
class NoteStateUpdateCommand extends NoteCommand {
final NoteState from;
final NoteState to;
/// Create a [NoteCommand] to update state of a note [from] the current state [to] another.
NoteStateUpdateCommand({
@required String id,
@required String uid,
@required this.from,
@required this.to,
}) : super(id: id, uid: uid);
@override
String get message {
switch (to) {
case NoteState.deleted:
return 'Note moved to trash';
case NoteState.archived:
return 'Note archived';
...
}
}
@override
Future<void> execute() => updateNoteState(to, id, uid);
@override
Future<void> revert() => updateNoteState(from, id, uid);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment