showAlert static method

void showAlert(
  1. BuildContext context,
  2. String title,
  3. String description, {
  4. String firstButtonTitle = "Accept",
  5. String? secondButtonTitle,
  6. Function? firstButtonAction,
  7. Function? secondButtonAction,
  8. Brightness? brightness,
})

Helper method used to open alarm with given title and description.

Implementation

static void showAlert(
  BuildContext context,
  String title,
  String description, {
  String firstButtonTitle = "Accept",
  String? secondButtonTitle,
  Function? firstButtonAction,
  Function? secondButtonAction,
  Brightness? brightness,
}) {
  List<Widget> actions = [];
  actions.add(
    TextButton(
      child: Text(firstButtonTitle),
      onPressed: () {
        if (firstButtonAction != null) {
          firstButtonAction();
        }
        Navigator.of(context).pop();
      },
    ),
  );
  if (secondButtonTitle != null) {
    actions.add(
      TextButton(
        child: Text(secondButtonTitle),
        onPressed: () {
          if (secondButtonAction != null) {
            secondButtonAction();
          }
          Navigator.of(context).pop();
        },
      ),
    );
  }
  showDialog(
    context: context,
    builder: (BuildContext buildContext) {
      return Theme(
        data: ThemeData(
          brightness: brightness ?? Brightness.light,
        ),
        child: AlertDialog(
          title: Text(title),
          content: Text(description),
          actions: actions,
        ),
      );
    },
  );
}