fix: Cupertino text dialogs
This commit is contained in:
parent
70c5f03e8d
commit
9eb1f4fc1e
2 changed files with 78 additions and 78 deletions
|
|
@ -64,20 +64,23 @@ class DialogTextField extends StatelessWidget {
|
||||||
);
|
);
|
||||||
case TargetPlatform.iOS:
|
case TargetPlatform.iOS:
|
||||||
case TargetPlatform.macOS:
|
case TargetPlatform.macOS:
|
||||||
|
final placeholder = labelText ?? hintText;
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
children: [
|
||||||
CupertinoTextField(
|
SizedBox(
|
||||||
controller: controller,
|
height: placeholder == null ? null : ((maxLines ?? 1) + 1) * 20,
|
||||||
obscureText: obscureText,
|
child: CupertinoTextField(
|
||||||
minLines: minLines,
|
controller: controller,
|
||||||
maxLines: maxLines,
|
obscureText: obscureText,
|
||||||
maxLength: maxLength,
|
minLines: minLines,
|
||||||
keyboardType: keyboardType,
|
maxLines: maxLines,
|
||||||
autocorrect: autocorrect,
|
maxLength: maxLength,
|
||||||
prefix: prefixText != null ? Text(prefixText) : null,
|
keyboardType: keyboardType,
|
||||||
suffix: suffixText != null ? Text(suffixText) : null,
|
autocorrect: autocorrect,
|
||||||
placeholder: labelText ?? hintText,
|
prefix: prefixText != null ? Text(prefixText) : null,
|
||||||
|
suffix: suffixText != null ? Text(suffixText) : null,
|
||||||
|
placeholder: placeholder,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
if (errorText != null)
|
if (errorText != null)
|
||||||
Text(
|
Text(
|
||||||
|
|
|
||||||
|
|
@ -34,76 +34,73 @@ Future<String?> showTextInputDialog({
|
||||||
useRootNavigator: useRootNavigator,
|
useRootNavigator: useRootNavigator,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
final error = ValueNotifier<String?>(null);
|
final error = ValueNotifier<String?>(null);
|
||||||
return ConstrainedBox(
|
return AlertDialog.adaptive(
|
||||||
constraints: const BoxConstraints(maxWidth: 512),
|
title: ConstrainedBox(
|
||||||
child: AlertDialog.adaptive(
|
constraints: const BoxConstraints(maxWidth: 256),
|
||||||
title: ConstrainedBox(
|
child: Text(title),
|
||||||
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,
|
|
||||||
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<String>(input);
|
|
||||||
},
|
|
||||||
autofocus: true,
|
|
||||||
child: Text(
|
|
||||||
okLabel ?? L10n.of(context).ok,
|
|
||||||
style: isDestructive
|
|
||||||
? TextStyle(color: Theme.of(context).colorScheme.error)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
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,
|
||||||
|
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<String>(input);
|
||||||
|
},
|
||||||
|
autofocus: true,
|
||||||
|
child: Text(
|
||||||
|
okLabel ?? L10n.of(context).ok,
|
||||||
|
style: isDestructive
|
||||||
|
? TextStyle(color: Theme.of(context).colorScheme.error)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue