fix: Textfields in dialogs on iOS

pull/1577/head rc1.24.0-1
Krille 9 months ago
parent 359399df21
commit b841d8c09e
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -24,8 +25,9 @@ Future<String?> showTextInputDialog({
TextInputType? keyboardType, TextInputType? keyboardType,
int? maxLength, int? maxLength,
bool autocorrect = true, bool autocorrect = true,
}) => }) {
showAdaptiveDialog<String>( final theme = Theme.of(context);
return showAdaptiveDialog<String>(
context: context, context: context,
useRootNavigator: useRootNavigator, useRootNavigator: useRootNavigator,
builder: (context) { builder: (context) {
@ -42,16 +44,19 @@ Future<String?> showTextInputDialog({
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
if (message != null) if (message != null)
Padding( ConstrainedBox(
padding: const EdgeInsets.only(bottom: 16.0),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 256), constraints: const BoxConstraints(maxWidth: 256),
child: Text(message), child: Text(message),
), ),
), const SizedBox(height: 16),
ValueListenableBuilder<String?>( ValueListenableBuilder<String?>(
valueListenable: error, valueListenable: error,
builder: (context, error, _) { builder: (context, error, _) {
switch (theme.platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
return TextField( return TextField(
controller: controller, controller: controller,
obscureText: obscureText, obscureText: obscureText,
@ -68,6 +73,37 @@ Future<String?> showTextInputDialog({
suffixText: suffixText, suffixText: suffixText,
), ),
); );
case TargetPlatform.iOS:
case TargetPlatform.macOS:
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,
),
if (error != null)
Text(
error,
style: TextStyle(
fontSize: 11,
color: theme.colorScheme.error,
),
textAlign: TextAlign.left,
),
],
);
}
}, },
), ),
], ],
@ -100,3 +136,4 @@ Future<String?> showTextInputDialog({
); );
}, },
); );
}

Loading…
Cancel
Save