promise<T> method
Implementation
String promise<T>(
Future<T> future, {
required String loading,
required String Function(T) success,
required String Function(Object) error,
String? title,
ToastPosition? position,
}) {
final id = this.loading(loading, title: title, position: position);
future.then((result) {
update(
id,
(t) => t.copyWith(
message: success(result),
variant: ToastVariant.success,
duration: 4000,
dismissible: true,
));
}).catchError((e) {
update(
id,
(t) => t.copyWith(
message: error(e),
variant: ToastVariant.error,
duration: 6000,
dismissible: true,
));
});
return id;
}