showTextAnswerDialog function Null safety

Future<bool> showTextAnswerDialog(
  1. {required BuildContext context,
  2. required String keyword,
  3. String? title,
  4. String? message,
  5. String? okLabel,
  6. String? cancelLabel,
  7. bool isDestructiveAction = false,
  8. bool barrierDismissible = true,
  9. String? hintText,
  10. String? retryTitle,
  11. String? retryMessage,
  12. String? retryOkLabel,
  13. String? retryCancelLabel,
  14. AdaptiveStyle? style,
  15. bool useRootNavigator = true,
  16. VerticalDirection actionsOverflowDirection = VerticalDirection.up,
  17. bool fullyCapitalizedForMaterial = true,
  18. WillPopCallback? onWillPop,
  19. bool autoSubmit = false,
  20. bool isCaseSensitive = true,
  21. AdaptiveDialogBuilder? builder}
)

Implementation

Future<bool> showTextAnswerDialog({
  required BuildContext context,
  required String keyword,
  String? title,
  String? message,
  String? okLabel,
  String? cancelLabel,
  bool isDestructiveAction = false,
  bool barrierDismissible = true,
  String? hintText,
  String? retryTitle,
  String? retryMessage,
  String? retryOkLabel,
  String? retryCancelLabel,
  AdaptiveStyle? style,
  bool useRootNavigator = true,
  VerticalDirection actionsOverflowDirection = VerticalDirection.up,
  bool fullyCapitalizedForMaterial = true,
  WillPopCallback? onWillPop,
  bool autoSubmit = false,
  bool isCaseSensitive = true,
  AdaptiveDialogBuilder? builder,
}) async {
  final adaptiveStyle = style ?? AdaptiveDialog.instance.defaultStyle;
  final texts = await showTextInputDialog(
    context: context,
    textFields: [
      DialogTextField(hintText: hintText),
    ],
    title: title,
    message: message,
    okLabel: okLabel,
    cancelLabel: cancelLabel,
    isDestructiveAction: isDestructiveAction,
    style: adaptiveStyle,
    actionsOverflowDirection: actionsOverflowDirection,
    fullyCapitalizedForMaterial: fullyCapitalizedForMaterial,
    onWillPop: onWillPop,
    autoSubmit: autoSubmit,
    builder: builder,
  );
  final text = texts == null ? null : texts[0];
  if (text == null) {
    return false;
  }
  if (isCaseSensitive
      ? text == keyword
      : text.toUpperCase() == keyword.toUpperCase()) {
    return true;
  }
  final result = await showOkCancelAlertDialog(
    context: context,
    title: retryTitle,
    message: retryMessage,
    okLabel: retryOkLabel,
    cancelLabel: retryCancelLabel,
    defaultType: OkCancelAlertDefaultType.ok,
    actionsOverflowDirection: actionsOverflowDirection,
    barrierDismissible: barrierDismissible,
    useRootNavigator: useRootNavigator,
    fullyCapitalizedForMaterial: fullyCapitalizedForMaterial,
    onWillPop: onWillPop,
    builder: builder,
  );
  return result == OkCancelResult.ok
      ? showTextAnswerDialog(
          context: context,
          keyword: keyword,
          title: title,
          message: message,
          okLabel: okLabel,
          cancelLabel: cancelLabel,
          isDestructiveAction: isDestructiveAction,
          barrierDismissible: barrierDismissible,
          hintText: hintText,
          retryTitle: retryTitle,
          retryMessage: retryMessage,
          retryOkLabel: retryOkLabel,
          retryCancelLabel: retryCancelLabel,
          style: style,
          useRootNavigator: useRootNavigator,
          actionsOverflowDirection: actionsOverflowDirection,
          fullyCapitalizedForMaterial: fullyCapitalizedForMaterial,
          onWillPop: onWillPop,
          autoSubmit: autoSubmit,
          builder: builder,
        )
      : Future.value(false);
}