showCancelConfirmationDialog method

void showCancelConfirmationDialog()

Implementation

void showCancelConfirmationDialog() {
  final key =
      widget.task.isConsentTask ? 'cancel_confirmation' : 'discard_confirmation';

  showDialog<dynamic>(
    context: context,
    builder: (BuildContext context) {
      final locale = RPLocalizations.of(context);
      return AlertDialog(
        title: Text(locale?.translate(key) ??
            (widget.task.isConsentTask
                ? "Leave consent form?"
                : "Leave survey?")),
        content: Text(locale?.translate('${key}_body') ??
            (widget.task.isConsentTask
                ? "You have not given your consent yet."
                : "Your answers will not be saved.")),
        actions: <Widget>[
          OutlinedButton(
            onPressed: () =>
                Navigator.of(context).pop(), // Dismissing the pop-up
            child: Text(locale?.translate('CANCEL') ?? "CANCEL"),
          ),
          FilledButton(
            onPressed: () {
              widget.onCancel?.call(_taskResult);
              Navigator.of(context).pop();
              if (Navigator.of(context).canPop()) {
                Navigator.of(context).pop();
              }
            },
            child: Text(locale?.translate('LEAVE') ?? "LEAVE"),
          ),
        ],
      );
    },
  );
}