Skip to content

Instantly share code, notes, and snippets.

@xinthink
Created March 5, 2020 10:04
Show Gist options
  • Save xinthink/55d100dbcce13b11a025701218b3caf6 to your computer and use it in GitHub Desktop.
Save xinthink/55d100dbcce13b11a025701218b3caf6 to your computer and use it in GitHub Desktop.
mixin CommandHandler<T extends StatefulWidget> on State<T> {
/// Processes the given [command].
Future<void> processNoteCommand(ScaffoldState scaffoldState, NoteCommand command) async {
if (command == null) {
return;
}
await command.execute();
final msg = command.message;
if (mounted && msg?.isNotEmpty == true) {
scaffoldState?.showSnackBar(SnackBar(
content: Text(msg),
action: SnackBarAction(
label: 'Undo',
onPressed: () => command.revert(),
),
));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment