What is the difference between:
Future<void>, async, await, then, catchError
Future<void> copyToClipboard(BuildContext context, String text) async {
await Clipboard.setData(ClipboardData(text: text))
.then((_) => showSnackBar(context, 'Copied to clipboard'))
.catchError((Object error) => showSnackBar(context, 'Error $error'));
}
void, async, await, then, catchError
void copyToClipboard(BuildContext context, String text) async {
await Clipboard.setData(ClipboardData(text: text))
.then((_) => showSnackBar(context, 'Copied to clipboard'))
.catchError((Object error) => showSnackBar(context, 'Error $error'));
}
void, then, catchError
void copyToClipboard(BuildContext context, String text) {
Clipboard.setData(ClipboardData(text: text))
.then((_) => showSnackBar(context, 'Copied to clipboard'))
.catchError((Object error) => showSnackBar(context, 'Error $error'));
}
All methods work. If I'm using then
and catchError
, do I still need to wrap the code in an async
function?
Which is the recommended way?