chore: Merge upstream changes --------- Signed-off-by: Krille <c.kussowski@famedly.com> Co-authored-by: krille-chan <christian-kussowski@posteo.de> Co-authored-by: Krille <c.kussowski@famedly.com> Co-authored-by: Linerly <linerly@proton.me> Co-authored-by: Priit Jõerüüt <hwlate@joeruut.com> Co-authored-by: 大王叫我来巡山 <hamburger2048@users.noreply.hosted.weblate.org> Co-authored-by: fadelkon <fadelkon@posteo.net> Co-authored-by: Aindriú Mac Giolla Eoin <aindriu80@gmail.com> Co-authored-by: Edgars Andersons <Edgars+Weblate@gaitenis.id.lv> Co-authored-by: josé m <correoxm@disroot.org> Co-authored-by: Bezruchenko Simon <worcposj44@gmail.com> Co-authored-by: Christian <christian-pauly@posteo.de> Co-authored-by: - <hitekex@yandex.ru> Co-authored-by: Angelo Schirinzi <Odi-3@users.noreply.hosted.weblate.org> Co-authored-by: xabirequejo <xabi.rn@gmail.com> Co-authored-by: Piotr Orzechowski <piotr@orzechowski.tech> Co-authored-by: Rex_sa <rex.sa@pm.me> Co-authored-by: Tewuzij <tenajeza@outlook.com> Co-authored-by: goknarbahceli <goknarbahceli@proton.me> Co-authored-by: தமிழ்நேரம் <anishprabu.t@gmail.com> Co-authored-by: Erin <erin@erindesu.cz> Co-authored-by: EpicKiwi <me@epickiwi.fr> Co-authored-by: Christian Tietze <me@christiantietze.de> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
155 lines
5.6 KiB
Dart
155 lines
5.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:fluffychat/widgets/adaptive_dialogs/adaptive_dialog_action.dart';
|
|
|
|
Future<String?> showTextInputDialog({
|
|
required BuildContext context,
|
|
required String title,
|
|
String? message,
|
|
String? okLabel,
|
|
String? cancelLabel,
|
|
bool useRootNavigator = true,
|
|
String? hintText,
|
|
String? labelText,
|
|
String? initialText,
|
|
String? prefixText,
|
|
String? suffixText,
|
|
bool obscureText = false,
|
|
bool isDestructive = false,
|
|
int? minLines,
|
|
int? maxLines,
|
|
String? Function(String input)? validator,
|
|
TextInputType? keyboardType,
|
|
int? maxLength,
|
|
bool autocorrect = true,
|
|
// #Pangea
|
|
bool autoSubmit = false,
|
|
// Pangea#
|
|
}) {
|
|
final theme = Theme.of(context);
|
|
return showAdaptiveDialog<String>(
|
|
context: context,
|
|
useRootNavigator: useRootNavigator,
|
|
builder: (context) {
|
|
final controller = TextEditingController(text: initialText);
|
|
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: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (message != null)
|
|
ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 256),
|
|
child: Text(message),
|
|
),
|
|
const SizedBox(height: 16),
|
|
ValueListenableBuilder<String?>(
|
|
valueListenable: error,
|
|
builder: (context, error, _) {
|
|
switch (theme.platform) {
|
|
case TargetPlatform.android:
|
|
case TargetPlatform.fuchsia:
|
|
case TargetPlatform.linux:
|
|
case TargetPlatform.windows:
|
|
return TextField(
|
|
controller: controller,
|
|
obscureText: obscureText,
|
|
minLines: minLines,
|
|
maxLines: maxLines,
|
|
maxLength: maxLength,
|
|
keyboardType: keyboardType,
|
|
autocorrect: autocorrect,
|
|
decoration: InputDecoration(
|
|
errorText: error,
|
|
hintText: hintText,
|
|
labelText: labelText,
|
|
prefixText: prefixText,
|
|
suffixText: suffixText,
|
|
),
|
|
// #Pangea
|
|
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#
|
|
);
|
|
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,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
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,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|