run method
Any event who needs to request api or delay must use it.
Implementation
Future<void> run(final Future<void> Function() onPressed,
{String? event, bool showToast = true}) async {
mLogger.d('[ButtonController] [$event] Start call run().');
// Check if any button is currently being processed
if (!MButtonController.to.isProcessing) {
mLogger.d('[ButtonController] [$event] The event is free.');
MButtonController.to.isProcessing = true;
/// The event start.
try {
await onPressed();
}
// We must use the fan else will be not execute set is a isProcessing to false when error.
finally {
/// The event done.
MButtonController.to.isProcessing = false;
}
} else {
mLogger.d('[ButtonController] The event $event inProcess.');
/// Some event is isProcessing.
if (showToast) {
mShowCustomToast("in process.".tr);
}
}
}