121 lines
3.8 KiB
Dart
121 lines
3.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,
|
|
required this.onSavePressed,
|
|
this.selectedBookmark,
|
|
this.selectedMapsLink,
|
|
});
|
|
final void Function(Bookmark bookmark) onSavePressed;
|
|
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;
|
|
}
|
|
|
|
return AlertDialog(
|
|
title: Text('Create Bookmark'),
|
|
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: [
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: Text('Cancel'),
|
|
),
|
|
FloatingActionButton(
|
|
onPressed: () {
|
|
onSavePressed(
|
|
Bookmark(
|
|
collectionId: collectionId,
|
|
name: nameController.text,
|
|
link: linkController.text,
|
|
description: descriptionController.text,
|
|
),
|
|
);
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Icon(Icons.save),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|