From ea9142b5522b56e20cefbd47559c3ba4d5d16534 Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Tue, 25 Feb 2025 13:50:35 -0500 Subject: [PATCH] fix: make text dialog autosubmit work as expected (#1918) --- .../show_text_input_dialog.dart | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/widgets/adaptive_dialogs/show_text_input_dialog.dart b/lib/widgets/adaptive_dialogs/show_text_input_dialog.dart index 38a15cf54..9f017b086 100644 --- a/lib/widgets/adaptive_dialogs/show_text_input_dialog.dart +++ b/lib/widgets/adaptive_dialogs/show_text_input_dialog.dart @@ -63,19 +63,11 @@ Future showTextInputDialog({ return TextField( controller: controller, obscureText: obscureText, - minLines: minLines, - maxLines: maxLines, - maxLength: maxLength, - keyboardType: keyboardType, - autocorrect: autocorrect, - decoration: InputDecoration( - errorText: error, - hintText: hintText, - labelText: labelText, - prefixText: prefixText, - suffixText: suffixText, - ), // #Pangea + // minLines: minLines, + // maxLines: maxLines, + minLines: autoSubmit ? 1 : minLines, + maxLines: autoSubmit ? 1 : maxLines, onSubmitted: autoSubmit ? (_) { final input = controller.text; @@ -88,6 +80,16 @@ Future showTextInputDialog({ } : null, // Pangea# + maxLength: maxLength, + keyboardType: keyboardType, + autocorrect: autocorrect, + decoration: InputDecoration( + errorText: error, + hintText: hintText, + labelText: labelText, + prefixText: prefixText, + suffixText: suffixText, + ), ); case TargetPlatform.iOS: case TargetPlatform.macOS: @@ -97,8 +99,23 @@ Future showTextInputDialog({ CupertinoTextField( controller: controller, obscureText: obscureText, - minLines: minLines, - maxLines: maxLines, + // #Pangea + // minLines: minLines, + // maxLines: maxLines, + minLines: autoSubmit ? 1 : minLines, + maxLines: autoSubmit ? 1 : maxLines, + onSubmitted: autoSubmit + ? (_) { + final input = controller.text; + final errorText = validator?.call(input); + if (errorText != null) { + error = errorText; + return; + } + Navigator.of(context).pop(input); + } + : null, + // Pangea# maxLength: maxLength, keyboardType: keyboardType, autocorrect: autocorrect, @@ -110,7 +127,7 @@ Future showTextInputDialog({ ), if (error != null) Text( - error, + error!, style: TextStyle( fontSize: 11, color: theme.colorScheme.error,