Skip to content

Instantly share code, notes, and snippets.

@xinthink
Last active March 8, 2020 03:54
Show Gist options
  • Save xinthink/1f98ec3bca2fe7e8af8c161ffd9ad827 to your computer and use it in GitHub Desktop.
Save xinthink/1f98ec3bca2fe7e8af8c161ffd9ad827 to your computer and use it in GitHub Desktop.
extension NoteStateX on NoteState {
/// Checks if a note in this state can be edited.
bool get canEdit => this < NoteState.deleted;
/// Returns true if this state is preceding to the other one.
bool operator <(NoteState other) => (this?.index ?? 0) < (other?.index ?? 0);
/// Message describes the state transition.
String get message {
switch (this) {
case NoteState.deleted:
return 'Note moved to trash';
...
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment