fix: Textfields in dialogs on iOS
This commit is contained in:
parent
359399df21
commit
b841d8c09e
1 changed files with 107 additions and 70 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue