From 9eb1f4fc1e7c3e0a3323560ef0f655206d8717db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Sun, 19 Oct 2025 14:22:42 +0200 Subject: [PATCH] fix: Cupertino text dialogs --- .../adaptive_dialogs/dialog_text_field.dart | 27 ++-- .../show_text_input_dialog.dart | 135 +++++++++--------- 2 files changed, 81 insertions(+), 81 deletions(-) diff --git a/lib/widgets/adaptive_dialogs/dialog_text_field.dart b/lib/widgets/adaptive_dialogs/dialog_text_field.dart index c80147878..0d801bd4d 100644 --- a/lib/widgets/adaptive_dialogs/dialog_text_field.dart +++ b/lib/widgets/adaptive_dialogs/dialog_text_field.dart @@ -64,20 +64,23 @@ class DialogTextField extends StatelessWidget { ); case TargetPlatform.iOS: case TargetPlatform.macOS: + final placeholder = labelText ?? hintText; return Column( - mainAxisSize: MainAxisSize.min, children: [ - CupertinoTextField( - controller: controller, - obscureText: obscureText, - minLines: minLines, - maxLines: maxLines, - maxLength: maxLength, - keyboardType: keyboardType, - autocorrect: autocorrect, - prefix: prefixText != null ? Text(prefixText) : null, - suffix: suffixText != null ? Text(suffixText) : null, - placeholder: labelText ?? hintText, + SizedBox( + height: placeholder == null ? null : ((maxLines ?? 1) + 1) * 20, + child: CupertinoTextField( + controller: controller, + obscureText: obscureText, + minLines: minLines, + maxLines: maxLines, + maxLength: maxLength, + keyboardType: keyboardType, + autocorrect: autocorrect, + prefix: prefixText != null ? Text(prefixText) : null, + suffix: suffixText != null ? Text(suffixText) : null, + placeholder: placeholder, + ), ), if (errorText != null) Text( diff --git a/lib/widgets/adaptive_dialogs/show_text_input_dialog.dart b/lib/widgets/adaptive_dialogs/show_text_input_dialog.dart index 37d4fdee0..32fb5795c 100644 --- a/lib/widgets/adaptive_dialogs/show_text_input_dialog.dart +++ b/lib/widgets/adaptive_dialogs/show_text_input_dialog.dart @@ -34,76 +34,73 @@ Future showTextInputDialog({ useRootNavigator: useRootNavigator, builder: (context) { final error = ValueNotifier(null); - return ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 512), - child: AlertDialog.adaptive( - title: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 256), - child: Text(title), - ), - content: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 256), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - if (message != null) - SelectableLinkify( - text: message, - textScaleFactor: MediaQuery.textScalerOf(context).scale(1), - linkStyle: TextStyle( - color: Theme.of(context).colorScheme.primary, - decorationColor: Theme.of(context).colorScheme.primary, - ), - options: const LinkifyOptions(humanize: false), - onOpen: (url) => UrlLauncher(context, url.url).launchUrl(), - ), - const SizedBox(height: 16), - ValueListenableBuilder( - valueListenable: error, - builder: (context, error, _) { - return DialogTextField( - hintText: hintText, - errorText: error, - labelText: labelText, - controller: controller, - initialText: initialText, - prefixText: prefixText, - suffixText: suffixText, - minLines: minLines, - maxLines: maxLines, - maxLength: maxLength, - keyboardType: keyboardType, - ); - }, - ), - ], - ), - ), - actions: [ - AdaptiveDialogAction( - onPressed: () => Navigator.of(context).pop(null), - child: Text(cancelLabel ?? L10n.of(context).cancel), - ), - AdaptiveDialogAction( - onPressed: () { - final input = controller.text; - final errorText = validator?.call(input); - if (errorText != null) { - error.value = errorText; - return; - } - Navigator.of(context).pop(input); - }, - autofocus: true, - child: Text( - okLabel ?? L10n.of(context).ok, - style: isDestructive - ? TextStyle(color: Theme.of(context).colorScheme.error) - : null, - ), - ), - ], + return AlertDialog.adaptive( + title: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 256), + child: Text(title), ), + content: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 256), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + if (message != null) + SelectableLinkify( + text: message, + textScaleFactor: MediaQuery.textScalerOf(context).scale(1), + linkStyle: TextStyle( + color: Theme.of(context).colorScheme.primary, + decorationColor: Theme.of(context).colorScheme.primary, + ), + options: const LinkifyOptions(humanize: false), + onOpen: (url) => UrlLauncher(context, url.url).launchUrl(), + ), + const SizedBox(height: 16), + ValueListenableBuilder( + valueListenable: error, + builder: (context, error, _) { + return DialogTextField( + hintText: hintText, + errorText: error, + labelText: labelText, + controller: controller, + initialText: initialText, + prefixText: prefixText, + suffixText: suffixText, + minLines: minLines, + maxLines: maxLines, + maxLength: maxLength, + keyboardType: keyboardType, + ); + }, + ), + ], + ), + ), + actions: [ + AdaptiveDialogAction( + onPressed: () => Navigator.of(context).pop(null), + child: Text(cancelLabel ?? L10n.of(context).cancel), + ), + AdaptiveDialogAction( + onPressed: () { + final input = controller.text; + final errorText = validator?.call(input); + if (errorText != null) { + error.value = errorText; + return; + } + Navigator.of(context).pop(input); + }, + autofocus: true, + child: Text( + okLabel ?? L10n.of(context).ok, + style: isDestructive + ? TextStyle(color: Theme.of(context).colorScheme.error) + : null, + ), + ), + ], ); }, );