showTextAnswerDialog function

  1. @useResult
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. bool canPop = true,
  19. PopInvokedCallback? onPopInvoked,
  20. bool autoSubmit = false,
  21. bool isCaseSensitive = true,
  22. AdaptiveDialogBuilder? builder}
)

Implementation

@useResult
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,
  bool canPop = true,
  PopInvokedCallback? onPopInvoked,
  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,
    canPop: canPop,
    onPopInvoked: onPopInvoked,
    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,
    canPop: canPop,
    onPopInvoked: onPopInvoked,
    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,
          canPop: canPop,
          onPopInvoked: onPopInvoked,
          autoSubmit: autoSubmit,
          builder: builder,
        )
      : Future.value(false);
}