Flutter Create Alert Dialog with Yes No Cancel Buttons Android iOS Example

By default alert dialog message box has single OK button but sometimes app developer wants to add multiple buttons in Alert Dialog box. In Flutter we can add button in Alert dialog box using FlatButton widget. Alert dialog box with multiple choices is used to give multiple handling technique to the app user like user can press the OK button or press the No button and also press the Cancel button to give his opinion. So in this tutorial we would Flutter Create Alert Dialog with Yes No Cancel Buttons Android iOS Example Tutorial.

Contents in this project Flutter Create Alert Dialog with Yes No Cancel Buttons Android iOS Example Tutorial:

1. Import material.dart package in your project’s main.dart file.

2. Create void main runApp() method and call our main Root MyApp class here. This method is our default method.

3. Create our main Root class named as MyApp. In this class we would call AlertWithButtons extends StatefulWidget class. We have to use the Stateful class structure in order to show the Alert dialog because alert dialog box usages Application build context.

4. Create a class named as AlertWithButtons extends StatefulWidget. In this class we would call our child view class named as AlertWithButtonsWidget using createState() method. The createState() would enable the mutable state management in flutter application.

5. Crete a class named as AlertWithButtonsWidget extends State. This class would be our main Child view class in which we would make the Alert dialog box.

6. Create a function named as showAlert() with Application build context and inside our declared function we would make flutter’s inbuilt showDialog() method to display the Alert dialog.

  • title : Is used to display the Title of Alert dialog box title text.
  • content : Is used to display Alert dialog context text.

7. Create a Raised Button widget in Widget build area. We would call the showAlert() method on button press event.

8. Complete source code for main.dart file:

Screenshots:

Flutter Create Alert Dialog with Yes No Cancel Buttons Android iOS Example

Leave a Reply

Your email address will not be published. Required fields are marked *