How to make an AlertDialog in Flutter?

前端 未结 9 2651
小蘑菇
小蘑菇 2020-11-29 00:56

I am learning to build apps in Flutter. Now I have come to alert dialogs. I have done them before in Android and iOS, but how do I make an alert in Flutter?

Here are

9条回答
  •  有刺的猬
    2020-11-29 01:24

    showAlertDialog(BuildContext context, String message, String heading,
          String buttonAcceptTitle, String buttonCancelTitle) {
        // set up the buttons
        Widget cancelButton = FlatButton(
          child: Text(buttonCancelTitle),
          onPressed: () {},
        );
        Widget continueButton = FlatButton(
          child: Text(buttonAcceptTitle),
          onPressed: () {
    
          },
        );
    
        // set up the AlertDialog
        AlertDialog alert = AlertDialog(
          title: Text(heading),
          content: Text(message),
          actions: [
            cancelButton,
            continueButton,
          ],
        );
    
        // show the dialog
        showDialog(
          context: context,
          builder: (BuildContext context) {
            return alert;
          },
        );
      }
    

    called like:

    showAlertDialog(context, 'Are you sure you want to delete?', "AppName" , "Ok", "Cancel");
    

提交回复
热议问题