A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

69 lines
1.7 KiB

part of '../neon.dart';
Future<String?> showRenameDialog({
required final BuildContext context,
required final String title,
required final String value,
final Key? key,
}) async =>
showDialog<String?>(
context: context,
builder: (final context) => _RenameDialog(
title: title,
value: value,
key: key,
),
);
class _RenameDialog extends StatefulWidget {
const _RenameDialog({
required this.title,
required this.value,
super.key,
});
final String title;
final String value;
@override
State<_RenameDialog> createState() => _RenameDialogState();
}
class _RenameDialogState extends State<_RenameDialog> {
final formKey = GlobalKey<FormState>();
late final controller = TextEditingController()..text = widget.value;
void submit() {
if (formKey.currentState!.validate()) {
Navigator.of(context).pop(controller.text);
}
}
@override
Widget build(final BuildContext context) => CustomDialog(
title: Text(widget.title),
children: [
Form(
key: formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
TextFormField(
autofocus: true,
controller: controller,
validator: (final input) => validateNotEmpty(context, input),
onFieldSubmitted: (final _) {
submit();
},
),
ElevatedButton(
onPressed: submit,
child: Text(widget.title),
),
],
),
),
],
);
}