Example of Create Toast Message in Flutter for Android iOS

Hello friends, In today’s tutorial we would learn about Toast alert message in flutter. In now days toast is not much used by developers but since from the beginning toast is used in almost every android mobile application. Toast main purpose is to show a small notification on mobile screen with small duration. Toast is only used in Android apps and does not come inbuilt in iOS apps. But after Flutter came we can make Toast message for both Android and iOS apps. Today we’re using fluttertoast: ^8.0.8 Pub package in our project to create toast message in flutter for android iOS. So let’s get started 🙂 .

Contents in this project Example of Create Toast Message in Flutter for Android iOS :-

1. First of all we have to install fluttertoast Pub package in our flutter project. So open your flutter project Root directory in Command Prompt or Terminal and execute below command.

Screenshot after done installation :-

Example of Create Toast Message in Flutter for Android iOS2. Now open your project’s main.dart file and import material.dart and fluttertoast.dart package.

3. Creating void main runApp() method and call here our main MyApp class.

4. Creating our main MyApp extends StatelessWidget class. Here we would call our Child class ToastMessage().

5. Creating our Sub child class ToastMessage extends StatefulWidget. In this class we would make our main Child class ToastChild with createState() method to enable mutable state management.

6. Creating our main Child class ToastChild extends State<ToastMessage>.

7. Creating a FToast object named as fToast. This is the variable of package:fluttertoast/fluttertoast.dart .

8. Creating initState() inbuilt function and here we would make fToast as object of FToast class and initialize it.

9. Creating a custom widget named as customToast. This is our custom designed Toast message View.

10. Creating a function named as _showCustomToast(). This function is used to show custom designed toast message.

11. Creating another function named as _showDefaultToast(). It is used to show our old style default Toast message on screen.

12. Creating Widget Build area -> Here we would make 2 ElevatedButton and call each above function on it.

13. Complete source code for main.dart file :-

Screenshots :-

Example of Create Toast Message in Flutter for Android iOS

Leave a Reply

Your email address will not be published.