feat(workspace): refresh desktop editing experience and prepare 0.1.2
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
This commit is contained in:
1 parent
aa5255d1e4
commit
2e0033ce2d
260 files changed
+43963
-5591
No files matched your search
@@ -11,6 +11,7 @@ Future<String?> askName(
|
||||
String? description,
|
||||
String initialValue = '',
|
||||
String? submitLabel,
|
||||
Future<String?> Function(String name)? validateName,
|
||||
}) => showAppDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => _NameDialog(
|
||||
@@ -19,6 +20,7 @@ Future<String?> askName(
|
||||
description: description,
|
||||
initialValue: initialValue,
|
||||
submitLabel: submitLabel,
|
||||
validateName: validateName,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -29,12 +31,14 @@ class _NameDialog extends StatefulWidget {
|
||||
this.description,
|
||||
required this.initialValue,
|
||||
this.submitLabel,
|
||||
this.validateName,
|
||||
});
|
||||
final String title;
|
||||
final String label;
|
||||
final String? description;
|
||||
final String initialValue;
|
||||
final String? submitLabel;
|
||||
final Future<String?> Function(String name)? validateName;
|
||||
@override
|
||||
State<_NameDialog> createState() => _NameDialogState();
|
||||
}
|
||||
@@ -46,16 +50,39 @@ class _NameDialogState extends State<_NameDialog> {
|
||||
extentOffset: widget.initialValue.length,
|
||||
);
|
||||
final _form = GlobalKey<FormState>();
|
||||
bool _validating = false;
|
||||
String? _validationError;
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
if (_form.currentState!.validate()) {
|
||||
Navigator.pop(context, _controller.text.trim());
|
||||
Future<void> _submit() async {
|
||||
if (_validating) return;
|
||||
_validationError = null;
|
||||
if (!_form.currentState!.validate()) return;
|
||||
final name = _controller.text.trim();
|
||||
if (widget.validateName != null) {
|
||||
setState(() => _validating = true);
|
||||
String? error;
|
||||
try {
|
||||
error = await widget.validateName!(name);
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
error = context.l10n.operationFailed;
|
||||
}
|
||||
if (!mounted || ModalRoute.of(context)?.isCurrent != true) return;
|
||||
setState(() {
|
||||
_validating = false;
|
||||
_validationError = error;
|
||||
});
|
||||
if (error != null) {
|
||||
_form.currentState!.validate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mounted) Navigator.pop(context, name);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -69,7 +96,7 @@ class _NameDialogState extends State<_NameDialog> {
|
||||
child: Text(context.l10n.cancel),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _submit,
|
||||
onPressed: _validating ? null : _submit,
|
||||
child: Text(widget.submitLabel ?? context.l10n.create),
|
||||
),
|
||||
],
|
||||
@@ -78,8 +105,10 @@ class _NameDialogState extends State<_NameDialog> {
|
||||
key: _form,
|
||||
child: TextFormField(
|
||||
controller: _controller,
|
||||
readOnly: _validating,
|
||||
style: AppTheme.inputTextStyle(dialogContext),
|
||||
cursorHeight: AppTheme.inputCursorHeight(dialogContext),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
autofocus: true,
|
||||
maxLength: 80,
|
||||
buildCounter: (
|
||||
@@ -88,13 +117,22 @@ class _NameDialogState extends State<_NameDialog> {
|
||||
required isFocused,
|
||||
maxLength,
|
||||
}) => null,
|
||||
decoration: InputDecoration(hintText: widget.label),
|
||||
decoration: InputDecoration(
|
||||
hintText: widget.label,
|
||||
hintStyle: AppTheme.inputHintStyle(dialogContext),
|
||||
errorMaxLines: 3,
|
||||
),
|
||||
validator: (value) => value == null || value.trim().isEmpty
|
||||
? context.l10n.enterName
|
||||
: RegExp(r'[/\\\x00-\x1F]').hasMatch(value) ||
|
||||
['.', '..'].contains(value.trim())
|
||||
? context.l10n.invalidName
|
||||
: null,
|
||||
: _validationError,
|
||||
onChanged: (_) {
|
||||
if (_validationError == null) return;
|
||||
_validationError = null;
|
||||
_form.currentState!.validate();
|
||||
},
|
||||
onFieldSubmitted: (_) => _submit(),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user