Flutter Toast
Hello All,
In this article we will see how to use fluttertoast
plugin to show Toast Messages
Lets Get started,
Before moving forward features provided by this plugin are
Features
- Full Controll of the Toast UI & Duration
- Toasts will be queued
- Remove a toast
- Clear the queue
How Plugin Works
This package internally uses Overlay to show toasts and manges queue using List
Code
First things first we need to import package in pubspec.yaml
Now lets get started with code
Add import statement for the package in your app
Now declare a variable flutterToast
and intiate it in initState
Now we create a function to build the toast ui and show the toast
If you see _showToast
function we find toast
varibale which will be our toast UI you can coustamize it as per our needs.
Now this above peice of the code will trigger the package and show / add to queue
Now Call _showToast()
based on user action
To cancel all the toasts call
// To remove present shwoing toastflutterToast.removeCustomToast()// To clear the queueflutterToast.removeQueuedCustomToasts();
Demo
We can also use it for loading purpose also, give it a try and let me know
Thanks for your time
Hope you like it, if yes **clap & share.**