import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import '../model/collection.dart'; import 'edit_dialog_widgets/edit_dialog_actions.dart' show EditDialogActions; import 'edit_dialog_widgets/edit_dialog_title.dart'; class CreateBookmarkCollectionDialog extends StatelessWidget { const CreateBookmarkCollectionDialog({ super.key, required this.onSavePressed, this.onDeletePressed, this.selectedCollection, }); final void Function()? onDeletePressed; final void Function(Collection collection) onSavePressed; final Collection? selectedCollection; @override Widget build(BuildContext context) { final nameController = TextEditingController(); if (selectedCollection != null) { nameController.text = selectedCollection!.name; } return AlertDialog( title: EditDialogTitle( dialogType: DialogType.collection, onDeletePressed: onDeletePressed, ), content: TextField( controller: nameController, autofocus: true, maxLines: 1, maxLength: 50, inputFormatters: [ FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9äöüÄÖÜß\s]')), FilteringTextInputFormatter.deny(RegExp(r'\s\s+')), ], decoration: InputDecoration( // TODO: Localize labelText: 'Collection Name', border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)), ), ), actions: [ EditDialogActions( onSavePressed: () { final bookmark = selectedCollection?.copyWith(name: nameController.text) ?? Collection(name: nameController.text); onSavePressed(bookmark); Navigator.of(context).pop(); }, ), ], ); } }