150 lines
4.8 KiB
Dart
150 lines
4.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../model/bookmark.dart';
|
|
import '../model/maps_link_metadata.dart';
|
|
|
|
class CreateBookmarkDialog extends StatelessWidget {
|
|
const CreateBookmarkDialog({
|
|
super.key,
|
|
required this.collectionId,
|
|
this.onSavePressed,
|
|
this.onDeletePressed,
|
|
this.selectedBookmark,
|
|
this.selectedMapsLink,
|
|
});
|
|
final void Function(Bookmark bookmark)? onSavePressed;
|
|
final void Function()? onDeletePressed;
|
|
final int collectionId;
|
|
final Bookmark? selectedBookmark;
|
|
final MapsLinkMetadata? selectedMapsLink;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final nameController = TextEditingController();
|
|
final linkController = TextEditingController();
|
|
final descriptionController = TextEditingController();
|
|
|
|
if (selectedMapsLink != null) {
|
|
nameController.text = selectedMapsLink!.placeName;
|
|
linkController.text = selectedMapsLink!.url;
|
|
descriptionController.text = selectedMapsLink!.description;
|
|
} else if (selectedBookmark != null) {
|
|
nameController.text = selectedBookmark!.name;
|
|
linkController.text = selectedBookmark!.link;
|
|
descriptionController.text = selectedBookmark!.description;
|
|
}
|
|
|
|
return AlertDialog(
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text('Create Bookmark'),
|
|
|
|
if (selectedBookmark != null)
|
|
TextButton(
|
|
onPressed: () {
|
|
onDeletePressed?.call();
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text(
|
|
'Delete',
|
|
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
content: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
Padding(padding: EdgeInsetsGeometry.only(top: 10)),
|
|
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(
|
|
labelText: 'Bookmark Title',
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
),
|
|
),
|
|
TextField(
|
|
controller: linkController,
|
|
maxLines: 1,
|
|
maxLength: 50,
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.allow(
|
|
RegExp(r'[a-zA-Z0-9äöüÄÖÜß\s/:\.]'),
|
|
),
|
|
FilteringTextInputFormatter.deny(RegExp(r'\s\s+')),
|
|
],
|
|
decoration: InputDecoration(
|
|
labelText: 'Url',
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
),
|
|
),
|
|
TextField(
|
|
controller: descriptionController,
|
|
maxLines: 3,
|
|
maxLength: 300,
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.allow(
|
|
RegExp(r'[a-zA-Z0-9äöüÄÖÜß\s]'),
|
|
),
|
|
FilteringTextInputFormatter.deny(RegExp(r'\s\s+')),
|
|
],
|
|
decoration: InputDecoration(
|
|
labelText: 'Description',
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
actions: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: Text('Cancel'),
|
|
),
|
|
FloatingActionButton(
|
|
onPressed: () {
|
|
final bookmark =
|
|
selectedBookmark?.copyWith(
|
|
name: nameController.text,
|
|
link: linkController.text,
|
|
description: descriptionController.text,
|
|
) ??
|
|
Bookmark(
|
|
collectionId: collectionId,
|
|
name: nameController.text,
|
|
link: linkController.text,
|
|
description: descriptionController.text,
|
|
);
|
|
onSavePressed?.call(bookmark);
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Icon(Icons.save),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|