showCancelConfirmationDialog method

void showCancelConfirmationDialog()

Implementation

void showCancelConfirmationDialog() {
  showDialog<dynamic>(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text(widget.task.isConsentTask
            ? RPLocalizations.of(context)?.translate('cancel_confirmation') ??
                "Cancel?"
            : RPLocalizations.of(context)
                    ?.translate('discard_confirmation') ??
                "Discard results and quit?"),
        actions: <Widget>[
          ButtonTheme(
            minWidth: 70,
            child: TextButton(
              style: ButtonStyle(
                backgroundColor: MaterialStateProperty.all(
                    (CupertinoTheme.of(context).primaryColor ==
                            CupertinoColors.activeBlue)
                        ? Theme.of(context).primaryColor
                        : CupertinoTheme.of(context).primaryColor),
              ),
              child: Text(
                RPLocalizations.of(context)?.translate('NO') ?? "NO",
                style: const TextStyle(color: Colors.white),
              ),
              onPressed: () =>
                  Navigator.of(context).pop(), // Dismissing the pop-up
            ),
          ),
          OutlinedButton(
            child: Text(
              RPLocalizations.of(context)?.translate('YES') ?? "YES",
              style: TextStyle(
                  color: ((CupertinoTheme.of(context).primaryColor ==
                          CupertinoColors.activeBlue)
                      ? Theme.of(context).primaryColor
                      : CupertinoTheme.of(context).primaryColor)),
            ),
            onPressed: () {
              // Calling the onCancel method with which the developer can for
              // e.g. save the result on the device.
              // Only call it if it's not null
              widget.onCancel?.call(_taskResult);
              // Popup dismiss
              Navigator.of(context).pop();
              // Exit the Ordered Task
              Navigator.of(context).pop();
            },
          )
        ],
      );
    },
  );
}