You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature Request: Handle Loading States and Futures
Description
First of all, thank you for creating and maintaining the Toastification library. It has been incredibly helpful for managing user notifications in Flutter applications.
I recently came across a web technology called Sonner, which provides an interesting approach to handling asynchronous tasks such as promises. Sonner's API allows developers to pass a promise directly, and it automatically handles the loading, success, and error states when the promise resolves or rejects.
Inspired by this approach, I believe it would be a fantastic feature for Toastification to also handle Flutter's Futures in a similar way.
Proposal
I would like to propose adding support for handling loading states and Futures directly within the Toastification library. This could be achieved by:
Allowing developers to pass a Future to Toastification, and based on the state of the Future, the library could:
Display a "loading" toast while the Future is in progress.
Show a "success" toast when the Future completes successfully.
Display an "error" toast if the Future fails with an exception.
A simple V1 of this could be to add a new ToastificationType.loading to handle the loading states manually, with an upcoming plan of V2 of this feature of allowing the developer to pass directly the Future, with some defaults for loading, sucess and error cases
Considerations
When handling a Future,when it resolves, the toast must be updated, instead of creating a new toast.
This could be resolved in different ways. One of the could be that wen you call the show on each toast you could pass an optional toastId, updating that specific toast, instead of creating a new one:
final toastId = toastification.show(
context: context,
type:ToastificationType.loading, // New toast style
title:Text("Loading...."),
....
);
awaitFuture.delayed(Duration(seconds:3)); // Simulate an API call
toastification.show(
context: context,
type:ToastificationType.success,
title:Text("Operation succesfull"),
toastId: toastId // This will update the previous toast
....
);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Feature Request: Handle Loading States and Futures
Description
First of all, thank you for creating and maintaining the Toastification library. It has been incredibly helpful for managing user notifications in Flutter applications.
I recently came across a web technology called Sonner, which provides an interesting approach to handling asynchronous tasks such as promises. Sonner's API allows developers to pass a promise directly, and it automatically handles the
loading,success, anderrorstates when the promise resolves or rejects.Inspired by this approach, I believe it would be a fantastic feature for Toastification to also handle Flutter's Futures in a similar way.
Proposal
I would like to propose adding support for handling loading states and Futures directly within the Toastification library. This could be achieved by:
Futureto Toastification, and based on the state of theFuture, the library could:Futureis in progress.Futurecompletes successfully.Futurefails with an exception.Example Usage
A simple V1 of this could be to add a new
ToastificationType.loadingto handle the loading states manually, with an upcoming plan of V2 of this feature of allowing the developer to pass directly theFuture, with some defaults for loading, sucess and error casesConsiderations
Future,when it resolves, the toast must be updated, instead of creating a new toast.showon each toast you could pass an optionaltoastId, updating that specific toast, instead of creating a new one:Beta Was this translation helpful? Give feedback.
All reactions