An example alert dialog. Retrieved from the material.io dialog page.

An alert dialog is a useful tool that alerts the app’s user. It is a pop up in the middle of the screen which places an overlay over the background. Most commonly, it is used to confirm one of the user’s potentially unrevertable actions. In this example, I will the setup to make one of these alert dialogs in the flutter framework.

First, you must call the showDialog() function, which alters the app’s state to show a dialog. You must provide the showDialog() function with a context and itemBuilder function. This itemBuilder function must return an object of type Dialog. In this example, we will return the most common option, the AlertDialog.

There are limitless possibilities for an AlertDialog, but here I will only give you the boiler-plate code to set one up. Here, various attributes can be set, including title, content, and actions. Actions are where you put the buttons, usually at the bottom of the dialog. The actions field takes in a list of widgets, therefore allowing you to put as many action widgets as you like.

For more information see the flutter.io page and the material.io page on dialogs.