added abilty to edit and delete collections
This commit is contained in:
@@ -1,18 +1,35 @@
|
||||
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(String name) onSavePressed;
|
||||
|
||||
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: Text('Create Collection'),
|
||||
title: EditDialogTitle(
|
||||
dialogType: DialogType.collection,
|
||||
onDeletePressed: onDeletePressed,
|
||||
),
|
||||
content: TextField(
|
||||
controller: nameController,
|
||||
autofocus: true,
|
||||
@@ -23,17 +40,20 @@ class CreateBookmarkCollectionDialog extends StatelessWidget {
|
||||
FilteringTextInputFormatter.deny(RegExp(r'\s\s+')),
|
||||
],
|
||||
decoration: InputDecoration(
|
||||
// TODO: Localize
|
||||
labelText: 'Collection Name',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
FloatingActionButton(
|
||||
onPressed: () {
|
||||
onSavePressed(nameController.text);
|
||||
EditDialogActions(
|
||||
onSavePressed: () {
|
||||
final bookmark =
|
||||
selectedCollection?.copyWith(name: nameController.text) ??
|
||||
Collection(name: nameController.text);
|
||||
onSavePressed(bookmark);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Icon(Icons.save),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'package:flutter/services.dart';
|
||||
|
||||
import '../model/bookmark.dart';
|
||||
import '../model/maps_link_metadata.dart';
|
||||
import 'edit_dialog_widgets/edit_dialog_actions.dart';
|
||||
import 'edit_dialog_widgets/edit_dialog_title.dart';
|
||||
|
||||
class CreateBookmarkDialog extends StatelessWidget {
|
||||
const CreateBookmarkDialog({
|
||||
@@ -13,6 +15,7 @@ class CreateBookmarkDialog extends StatelessWidget {
|
||||
this.selectedBookmark,
|
||||
this.selectedMapsLink,
|
||||
});
|
||||
|
||||
final void Function(Bookmark bookmark)? onSavePressed;
|
||||
final void Function()? onDeletePressed;
|
||||
final int collectionId;
|
||||
@@ -36,25 +39,10 @@ class CreateBookmarkDialog extends StatelessWidget {
|
||||
}
|
||||
|
||||
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),
|
||||
),
|
||||
),
|
||||
],
|
||||
title: EditDialogTitle(
|
||||
dialogType: DialogType.bookmark,
|
||||
onDeletePressed: onDeletePressed,
|
||||
),
|
||||
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -115,33 +103,23 @@ class CreateBookmarkDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
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),
|
||||
),
|
||||
],
|
||||
EditDialogActions(
|
||||
onSavePressed: () {
|
||||
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();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
22
lib/widgets/edit_dialog_widgets/edit_dialog_actions.dart
Normal file
22
lib/widgets/edit_dialog_widgets/edit_dialog_actions.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter/material.dart'
|
||||
show TextButton, FloatingActionButton, Icons;
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class EditDialogActions extends StatelessWidget {
|
||||
const EditDialogActions({super.key, required this.onSavePressed});
|
||||
final VoidCallback onSavePressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text('Cancel'),
|
||||
),
|
||||
FloatingActionButton(onPressed: onSavePressed, child: Icon(Icons.save)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
40
lib/widgets/edit_dialog_widgets/edit_dialog_title.dart
Normal file
40
lib/widgets/edit_dialog_widgets/edit_dialog_title.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart' show TextButton, Theme;
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class EditDialogTitle extends StatelessWidget {
|
||||
const EditDialogTitle({
|
||||
super.key,
|
||||
this.onDeletePressed,
|
||||
required this.dialogType,
|
||||
});
|
||||
final VoidCallback? onDeletePressed;
|
||||
final DialogType dialogType;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// TODO: Localize
|
||||
if (dialogType == DialogType.bookmark)
|
||||
Text('Create Bookmark')
|
||||
else
|
||||
Text('Create Collection'),
|
||||
|
||||
if (onDeletePressed != null)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
onDeletePressed!.call();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(
|
||||
'Delete',
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum DialogType { bookmark, collection }
|
||||
Reference in New Issue
Block a user