displayDialog function

dynamic displayDialog(
  1. BuildContext context, {
  2. String title = "",
  3. String content = "",
  4. Function? event,
  5. String? buttonText,
})

Implementation

displayDialog(BuildContext context,
    {String title = "", String content = "", Function? event, String? buttonText}) {
  showDialog(
      context: context,
      builder: (BuildContext context) {
        return  AlertDialog(
          title: Text(title),
          content: Text(content),
          actions: [
            ElevatedButton(
              child: Text(buttonText ?? "OK"),
              style: ElevatedButton.styleFrom(
                primary: Colors.green, // background
                onPrimary: Colors.white, // foreground
              ),
              // onPressed: event ?? () => Navigator.pop(context),

              onPressed: (){
                if(event !=null){
                  Navigator.pop(context);
                  event();
                }else{
                  Navigator.pop(context);
                }
              },

            ),
          ],
        );
      }
  );
}