fix: fix small text input boxes on iOS (#4719)

This commit is contained in:
ggurdin 2025-11-21 09:21:57 -05:00 committed by GitHub
parent a504b8b832
commit b5a7b1bef0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 102 additions and 100 deletions

View file

@ -10,7 +10,7 @@ class DialogTextField extends StatelessWidget {
final String? prefixText;
final String? suffixText;
final String? errorText;
final bool obscureText = false;
final bool obscureText;
final bool isDestructive = false;
final int? minLines;
final int? maxLines;
@ -35,6 +35,7 @@ class DialogTextField extends StatelessWidget {
this.controller,
this.counterText,
this.errorText,
this.obscureText = false,
// #Pangea
this.onSubmitted,
// Pangea#
@ -73,23 +74,26 @@ 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,
// #Pangea
onSubmitted: onSubmitted,
// Pangea#
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,
// #Pangea
onSubmitted: onSubmitted,
// Pangea#
),
),
if (errorText != null)
Text(

View file

@ -37,91 +37,89 @@ Future<String?> showTextInputDialog({
useRootNavigator: useRootNavigator,
builder: (context) {
final error = ValueNotifier<String?>(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<String?>(
valueListenable: error,
builder: (context, error, _) {
return DialogTextField(
hintText: hintText,
errorText: error,
labelText: labelText,
controller: controller,
initialText: initialText,
prefixText: prefixText,
suffixText: suffixText,
// #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<String>(input);
}
: null,
// Pangea#
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<String>(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<String?>(
valueListenable: error,
builder: (context, error, _) {
return DialogTextField(
hintText: hintText,
errorText: error,
labelText: labelText,
controller: controller,
initialText: initialText,
prefixText: prefixText,
suffixText: suffixText,
// #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<String>(input);
}
: null,
// Pangea#
maxLength: maxLength,
keyboardType: keyboardType,
obscureText: obscureText,
);
},
),
],
),
),
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<String>(input);
},
autofocus: true,
child: Text(
okLabel ?? L10n.of(context).ok,
style: isDestructive
? TextStyle(color: Theme.of(context).colorScheme.error)
: null,
),
),
],
);
},
);