Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove previous fired toast ? #169

Open
animeshrick opened this issue Nov 27, 2024 · 8 comments
Open

How to remove previous fired toast ? #169

animeshrick opened this issue Nov 27, 2024 · 8 comments
Labels
question Further information is requested

Comments

@animeshrick
Copy link

I want to automatically remove the first toast when a new one is fired, because currently, the toasts are stacking up.

I've set the duration to 5 seconds so that the user has enough time to read the message before it disappears.

autoCloseDuration: Duration(seconds: durationSeconds ?? 5),

Is there any documentation I should review carefully to resolve this?

Sharing an image for reference,

Screenshot_1732739165

@animeshrick animeshrick added the question Further information is requested label Nov 27, 2024
@rinsarmu
Copy link

rinsarmu commented Dec 16, 2024

i have struggled like you, to dismiss the previous toast message.
here is how I solve the issue.
`

ToastificationItem? _currentToast;
void customToast(BuildContext context,
{required String message, bool isError = true}) {

if (_currentToast != null) {
toastification.dismiss(_currentToast!);
_currentToast = null; // Reset the reference after dismissing
}

// Show the new toast and save its reference
_currentToast = toastification.show(
context: context,
backgroundColor: isError ? Colors.black : const Color(0xFFDDF7E0),
foregroundColor: Colors.white,
showProgressBar: false,
closeOnClick: true,
type: isError ? ToastificationType.error : ToastificationType.success,
style: ToastificationStyle.flat,
title: Text(
isError ? 'Error' : 'Success',

  ),
  description: Text(
    message,
  
  ),
  alignment: Alignment.topLeft,
  autoCloseDuration: const Duration(seconds: 6),
  closeButtonShowType: CloseButtonShowType.none);

`

@Vinicius-8
Copy link

I believe using "toastification.dismissAll();" before firing a new one should do the trick.

@dorklein
Copy link

dorklein commented Jan 6, 2025

When using toastification.show(...); and right after toastification.dismissAll(); It doesn't always dismiss it

@payam-zahedi
Copy link
Owner

@dorklein @Vinicius-8 @dorklein

What exactly is your problem?

Do you want to show only for example one toast on the page?

@dorklein
Copy link

dorklein commented Jan 6, 2025

@dorklein @Vinicius-8 @dorklein

What exactly is your problem?

Do you want to show only for example one toast on the page?

YES.

For example, I have a button to download a file, I want to show first a message "Downloading..." and when the download has finished immediately show a new Toast "Download successful". Sometimes when the download is fast, the dismissAll() Does not dismiss the first Toast

@payam-zahedi
Copy link
Owner

@dorklein Alright,

In the latest changes, we added a feature that allows you to limit the maximum number of toasts you want to show.

For example, you can set it to 1.

@payam-zahedi
Copy link
Owner

You will access to it in next version

@rinsarmu
Copy link

rinsarmu commented Jan 7, 2025

u

@dorklein @Vinicius-8 @dorklein
What exactly is your problem?
Do you want to show only for example one toast on the page?

YES.

For example, I have a button to download a file, I want to show first a message "Downloading..." and when the download has finished immediately show a new Toast "Download successful". Sometimes when the download is fast, the dismissAll() Does not dismiss the first Toast

i have found a trick from the documentation. u can dismiss it using the first toastedId. every toast has dedicated toastId. if u are curios to find the full code i have replied it before. u can use that, and it works 100%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants