Created
March 5, 2020 09:54
-
-
Save xinthink/5a292f5d1048bfd8577b2c41b861f51f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// when pressed, dissmiss the bottom sheet and return a command | |
IconButton( | |
icon: const Icon(Icons.archive), | |
tooltip: 'Archive', | |
onPressed: () => Navigator.pop(context, NoteStateUpdateCommand( | |
id: _note.id, | |
uid: uid, | |
from: _note.state, // the current state | |
to: NoteState.archived, // the transition target | |
)), | |
), | |
// receiving a command | |
void _showNoteBottomSheet(BuildContext context) async { | |
final command = await showModalBottomSheet<NoteCommand>( | |
... | |
); | |
if (command != null) { | |
processNoteCommand(_scaffoldKey.currentState, command); | |
} | |
} | |
/// Processes the given [command], displays a SnackBar. | |
Future<void> processNoteCommand(ScaffoldState scaffoldState, NoteCommand command) async { | |
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