added abilty to edit and delete collections
This commit is contained in:
@@ -7,12 +7,28 @@ class Collection {
|
|||||||
createdAt: json['createdAt'] as int,
|
createdAt: json['createdAt'] as int,
|
||||||
);
|
);
|
||||||
|
|
||||||
String name;
|
|
||||||
int createdAt; // used as Id with millisecondsSinceEpoch
|
int createdAt; // used as Id with millisecondsSinceEpoch
|
||||||
|
String name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (other is Collection) {
|
||||||
|
return hashCode == other.hashCode;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => id.hashCode;
|
||||||
|
|
||||||
int get id => createdAt;
|
int get id => createdAt;
|
||||||
|
|
||||||
DateTime get createdDate => DateTime.fromMillisecondsSinceEpoch(createdAt);
|
DateTime get createdDate => DateTime.fromMillisecondsSinceEpoch(createdAt);
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {'name': name, 'createdAt': createdAt};
|
Map<String, dynamic> toJson() => {'name': name, 'createdAt': createdAt};
|
||||||
|
|
||||||
|
Collection copyWith({String? name}) {
|
||||||
|
return Collection(name: name ?? this.name, createdAt: createdAt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ class CollectionPage extends StatefulWidget {
|
|||||||
class _CollectionPageState extends State<CollectionPage> {
|
class _CollectionPageState extends State<CollectionPage> {
|
||||||
MapsLinkMetadata? selectedMapsLink;
|
MapsLinkMetadata? selectedMapsLink;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (selectedMapsLink != null) onAddButtonPressed();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void onAddButtonPressed() => showDialog(
|
void onAddButtonPressed() => showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => CreateBookmarkDialog(
|
builder: (context) => CreateBookmarkDialog(
|
||||||
@@ -43,21 +51,13 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
if (selectedMapsLink != null) onAddButtonPressed();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void onBookmarkSaved(Bookmark bookmark) {
|
void onBookmarkSaved(Bookmark bookmark) {
|
||||||
Storage.addOrUpdateBookmark(bookmark);
|
Storage.addOrUpdateBookmark(bookmark);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
context.read<SharedLinkProvider>().removeCurrentMapsLink();
|
context.read<SharedLinkProvider>().removeCurrentMapsLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget bookmarkListBuilder(BuildContext context, Bookmark bookmark) {
|
Widget bookmarksListItemBuilder(BuildContext context, Bookmark bookmark) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(bookmark.name),
|
title: Text(bookmark.name),
|
||||||
onTap: () => launchUrlFromString(bookmark.link),
|
onTap: () => launchUrlFromString(bookmark.link),
|
||||||
@@ -95,7 +95,7 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||||||
),
|
),
|
||||||
body: ListView.builder(
|
body: ListView.builder(
|
||||||
itemBuilder: (context, index) =>
|
itemBuilder: (context, index) =>
|
||||||
bookmarkListBuilder(context, bookmarks.elementAt(index)),
|
bookmarksListItemBuilder(context, bookmarks.elementAt(index)),
|
||||||
itemCount: bookmarks.length,
|
itemCount: bookmarks.length,
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import 'collection_page.dart';
|
|||||||
|
|
||||||
class CollectionsListPage extends StatefulWidget {
|
class CollectionsListPage extends StatefulWidget {
|
||||||
const CollectionsListPage({super.key});
|
const CollectionsListPage({super.key});
|
||||||
|
|
||||||
static const String routeName = '/collections';
|
static const String routeName = '/collections';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -17,11 +18,63 @@ class CollectionsListPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _CollectionsListPageState extends State<CollectionsListPage> {
|
class _CollectionsListPageState extends State<CollectionsListPage> {
|
||||||
final collections = Storage.loadCollections();
|
|
||||||
bool addingNewBookmark = false;
|
bool addingNewBookmark = false;
|
||||||
|
|
||||||
|
Widget bottomSheetBuilder(BuildContext context) {
|
||||||
|
final titleTextFieldController = TextEditingController(
|
||||||
|
text: context
|
||||||
|
.read<SharedLinkProvider>()
|
||||||
|
.currentMapsLinkMetadata!
|
||||||
|
.placeName,
|
||||||
|
);
|
||||||
|
return SizedBox(
|
||||||
|
height: 200,
|
||||||
|
child: TextField(controller: titleTextFieldController),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onAddButtonPressed() => showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) =>
|
||||||
|
CreateBookmarkCollectionDialog(onSavePressed: onCollectionSaved),
|
||||||
|
);
|
||||||
|
|
||||||
|
void onCollectionSaved(Collection collection) {
|
||||||
|
Storage.addOrUpdateCollection(collection);
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget collectionsListItemBuilder(
|
||||||
|
BuildContext context,
|
||||||
|
Collection collection,
|
||||||
|
) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(collection.name),
|
||||||
|
onTap: () => navigateToCollection(collection.id),
|
||||||
|
onLongPress: () => onEditCollection(collection),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void navigateToCollection(int collectionId) {
|
||||||
|
BookmarksProvider.selectedCollectionId = collectionId;
|
||||||
|
Navigator.pushNamed(context, CollectionPage.routeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onEditCollection(Collection selectedCollection) => showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => CreateBookmarkCollectionDialog(
|
||||||
|
selectedCollection: selectedCollection,
|
||||||
|
onSavePressed: onCollectionSaved,
|
||||||
|
onDeletePressed: () {
|
||||||
|
Storage.deleteCollection(selectedCollection);
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final collections = Storage.loadCollections();
|
||||||
final provider = context.watch<SharedLinkProvider>();
|
final provider = context.watch<SharedLinkProvider>();
|
||||||
addingNewBookmark = provider.currentMapsLinkMetadata != null;
|
addingNewBookmark = provider.currentMapsLinkMetadata != null;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -40,58 +93,10 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
|
|||||||
child: Icon(Icons.add),
|
child: Icon(Icons.add),
|
||||||
),
|
),
|
||||||
body: ListView.builder(
|
body: ListView.builder(
|
||||||
itemBuilder: itemBuilder,
|
itemBuilder: (context, index) =>
|
||||||
|
collectionsListItemBuilder(context, collections.elementAt(index)),
|
||||||
itemCount: collections.length,
|
itemCount: collections.length,
|
||||||
),
|
),
|
||||||
// bottomSheet: provider.currentMapsLinkMetadata == null
|
|
||||||
// ? null
|
|
||||||
// : BottomSheet(onClosing: () {}, builder: bottomSheetBuilder),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget bottomSheetBuilder(BuildContext context) {
|
|
||||||
final titleTextFieldController = TextEditingController(
|
|
||||||
text: context
|
|
||||||
.read<SharedLinkProvider>()
|
|
||||||
.currentMapsLinkMetadata!
|
|
||||||
.placeName,
|
|
||||||
);
|
|
||||||
return SizedBox(
|
|
||||||
height: 200,
|
|
||||||
child: TextField(controller: titleTextFieldController),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onAddButtonPressed() =>
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) =>
|
|
||||||
CreateBookmarkCollectionDialog(onSavePressed: onCollectionSaved),
|
|
||||||
).whenComplete(() {
|
|
||||||
if (addingNewBookmark) navigateToCollection(collections.last.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
void onCollectionSaved(String name) {
|
|
||||||
collections.add(Collection(name: name));
|
|
||||||
Storage.saveCollections(collections);
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget itemBuilder(BuildContext context, int index) {
|
|
||||||
final collection = collections.elementAt(index);
|
|
||||||
return ListTile(
|
|
||||||
title: Text(collection.name),
|
|
||||||
onTap: () => navigateToCollection(collection.id),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void navigateToCollection(int collectionId) {
|
|
||||||
BookmarksProvider.selectedCollectionId = collectionId;
|
|
||||||
Navigator.pushNamed(context, CollectionPage.routeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didChangeDependencies() {
|
|
||||||
super.didChangeDependencies();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import '../model/bookmark.dart';
|
|||||||
import '../model/collection.dart';
|
import '../model/collection.dart';
|
||||||
|
|
||||||
class Storage {
|
class Storage {
|
||||||
static const String _collectionsKey = 'collections';
|
|
||||||
static const String _bookmarksKey = 'bookmarks';
|
static const String _bookmarksKey = 'bookmarks';
|
||||||
static const String _statsKey = 'stats';
|
static const String _collectionsKey = 'collections';
|
||||||
static SharedPreferencesWithCache? _prefsWithCache;
|
static SharedPreferencesWithCache? _prefsWithCache;
|
||||||
|
static const String _statsKey = 'stats';
|
||||||
|
|
||||||
static Future<void> initialize() async {
|
static Future<void> initialize() async {
|
||||||
_prefsWithCache = await SharedPreferencesWithCache.create(
|
_prefsWithCache = await SharedPreferencesWithCache.create(
|
||||||
@@ -19,15 +19,6 @@ class Storage {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SharedPreferencesWithCache get _prefs {
|
|
||||||
if (_prefsWithCache == null) {
|
|
||||||
throw StateError(
|
|
||||||
'BookmarkStorage not initialized. Call initialize() first.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return _prefsWithCache!;
|
|
||||||
}
|
|
||||||
|
|
||||||
static List<Collection> loadCollections() {
|
static List<Collection> loadCollections() {
|
||||||
final jsonString = _prefs.getString(_collectionsKey) ?? '[]';
|
final jsonString = _prefs.getString(_collectionsKey) ?? '[]';
|
||||||
final jsonList = jsonDecode(jsonString) as List;
|
final jsonList = jsonDecode(jsonString) as List;
|
||||||
@@ -36,12 +27,7 @@ class Storage {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> saveCollections(List<Collection> collections) async {
|
static List<Bookmark> loadBookmarks() {
|
||||||
final jsonList = collections.map((c) => c.toJson()).toList();
|
|
||||||
await _prefs.setString(_collectionsKey, jsonEncode(jsonList));
|
|
||||||
}
|
|
||||||
|
|
||||||
static List<Bookmark> loadAllBookmarks() {
|
|
||||||
final jsonString = _prefs.getString(_bookmarksKey) ?? '[]';
|
final jsonString = _prefs.getString(_bookmarksKey) ?? '[]';
|
||||||
final jsonList = jsonDecode(jsonString) as List;
|
final jsonList = jsonDecode(jsonString) as List;
|
||||||
return jsonList
|
return jsonList
|
||||||
@@ -49,42 +35,29 @@ class Storage {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> saveAllBookmarks(List<Bookmark> bookmarks) async {
|
static Future<void> saveCollections(List<Collection> collections) async {
|
||||||
|
final jsonList = collections.map((c) => c.toJson()).toList();
|
||||||
|
await _prefs.setString(_collectionsKey, jsonEncode(jsonList));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> saveBookmarks(List<Bookmark> bookmarks) async {
|
||||||
final jsonList = bookmarks.map((b) => b.toJson()).toList();
|
final jsonList = bookmarks.map((b) => b.toJson()).toList();
|
||||||
await _prefs.setString(_bookmarksKey, jsonEncode(jsonList));
|
await _prefs.setString(_bookmarksKey, jsonEncode(jsonList));
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Bookmark> loadBookmarksForCollection(int collectionId) {
|
static List<Bookmark> loadBookmarksForCollection(int collectionId) {
|
||||||
final allBookmarks = loadAllBookmarks();
|
final allBookmarks = loadBookmarks();
|
||||||
return allBookmarks.where((b) => b.collectionId == collectionId).toList();
|
return allBookmarks.where((b) => b.collectionId == collectionId).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> addBookmark(Bookmark bookmark) async {
|
static Future<void> addBookmark(Bookmark bookmark) async {
|
||||||
final bookmarks = loadAllBookmarks();
|
final bookmarks = loadBookmarks();
|
||||||
bookmarks.add(bookmark);
|
bookmarks.add(bookmark);
|
||||||
await saveAllBookmarks(bookmarks);
|
await saveBookmarks(bookmarks);
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> deleteBookmark(Bookmark bookmark) async {
|
|
||||||
final bookmarks = loadAllBookmarks();
|
|
||||||
bookmarks.remove(bookmark);
|
|
||||||
await saveAllBookmarks(bookmarks);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> deleteBookmarkById(int bookmarkId) async {
|
|
||||||
final bookmarks = loadAllBookmarks();
|
|
||||||
bookmarks.removeWhere((b) => b.id == bookmarkId);
|
|
||||||
await saveAllBookmarks(bookmarks);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> deleteBookmarksForCollection(int collectionId) async {
|
|
||||||
final bookmarks = loadAllBookmarks();
|
|
||||||
bookmarks.removeWhere((b) => b.collectionId == collectionId);
|
|
||||||
await saveAllBookmarks(bookmarks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> addOrUpdateBookmark(Bookmark bookmark) async {
|
static Future<void> addOrUpdateBookmark(Bookmark bookmark) async {
|
||||||
final bookmarks = loadAllBookmarks();
|
final bookmarks = loadBookmarks();
|
||||||
final index = bookmarks.indexWhere((b) => b.id == bookmark.id);
|
final index = bookmarks.indexWhere((b) => b.id == bookmark.id);
|
||||||
|
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
@@ -92,7 +65,19 @@ class Storage {
|
|||||||
} else if (index >= 0) {
|
} else if (index >= 0) {
|
||||||
bookmarks[index] = bookmark;
|
bookmarks[index] = bookmark;
|
||||||
}
|
}
|
||||||
await saveAllBookmarks(bookmarks);
|
await saveBookmarks(bookmarks);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> addOrUpdateCollection(Collection collection) async {
|
||||||
|
final collections = loadCollections();
|
||||||
|
final index = collections.indexWhere((b) => b.id == collection.id);
|
||||||
|
|
||||||
|
if (index == -1) {
|
||||||
|
collections.add(collection);
|
||||||
|
} else if (index >= 0) {
|
||||||
|
collections[index] = collection;
|
||||||
|
}
|
||||||
|
await saveCollections(collections);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> updateBookmarkById(
|
static Future<void> updateBookmarkById(
|
||||||
@@ -101,7 +86,7 @@ class Storage {
|
|||||||
String? description,
|
String? description,
|
||||||
String? link,
|
String? link,
|
||||||
}) async {
|
}) async {
|
||||||
final bookmarks = loadAllBookmarks();
|
final bookmarks = loadBookmarks();
|
||||||
final index = bookmarks.indexWhere((b) => b.id == bookmarkId);
|
final index = bookmarks.indexWhere((b) => b.id == bookmarkId);
|
||||||
|
|
||||||
if (index == -1) return;
|
if (index == -1) return;
|
||||||
@@ -110,7 +95,34 @@ class Storage {
|
|||||||
if (description != null) bookmarks[index].description = description;
|
if (description != null) bookmarks[index].description = description;
|
||||||
if (link != null) bookmarks[index].link = link;
|
if (link != null) bookmarks[index].link = link;
|
||||||
|
|
||||||
await saveAllBookmarks(bookmarks);
|
await saveBookmarks(bookmarks);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> deleteBookmark(Bookmark bookmark) async {
|
||||||
|
final bookmarks = loadBookmarks();
|
||||||
|
bookmarks.remove(bookmark);
|
||||||
|
await saveBookmarks(bookmarks);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> deleteBookmarkById(int bookmarkId) async {
|
||||||
|
final bookmarks = loadBookmarks();
|
||||||
|
bookmarks.removeWhere((b) => b.id == bookmarkId);
|
||||||
|
await saveBookmarks(bookmarks);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> deleteBookmarksForCollection(int collectionId) async {
|
||||||
|
final bookmarks = loadBookmarks();
|
||||||
|
bookmarks.removeWhere((b) => b.collectionId == collectionId);
|
||||||
|
await saveBookmarks(bookmarks);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> deleteCollection(Collection collection) async {
|
||||||
|
final collections = loadCollections();
|
||||||
|
final bookmarks = loadBookmarks();
|
||||||
|
bookmarks.removeWhere((bookmark) => bookmark.collectionId == collection.id);
|
||||||
|
collections.remove(collection);
|
||||||
|
await saveBookmarks(bookmarks);
|
||||||
|
await saveCollections(collections);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, int> getStats() {
|
static Map<String, int> getStats() {
|
||||||
@@ -124,7 +136,7 @@ class Storage {
|
|||||||
|
|
||||||
static Future<void> updateStats() async {
|
static Future<void> updateStats() async {
|
||||||
final collections = loadCollections();
|
final collections = loadCollections();
|
||||||
final bookmarks = loadAllBookmarks();
|
final bookmarks = loadBookmarks();
|
||||||
|
|
||||||
final stats = {
|
final stats = {
|
||||||
'totalCollections': collections.length,
|
'totalCollections': collections.length,
|
||||||
@@ -134,4 +146,13 @@ class Storage {
|
|||||||
|
|
||||||
await _prefs.setString(_statsKey, jsonEncode(stats));
|
await _prefs.setString(_statsKey, jsonEncode(stats));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SharedPreferencesWithCache get _prefs {
|
||||||
|
if (_prefsWithCache == null) {
|
||||||
|
throw StateError(
|
||||||
|
'BookmarkStorage not initialized. Call initialize() first.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _prefsWithCache!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,35 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.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 {
|
class CreateBookmarkCollectionDialog extends StatelessWidget {
|
||||||
const CreateBookmarkCollectionDialog({
|
const CreateBookmarkCollectionDialog({
|
||||||
super.key,
|
super.key,
|
||||||
required this.onSavePressed,
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final nameController = TextEditingController();
|
final nameController = TextEditingController();
|
||||||
|
|
||||||
|
if (selectedCollection != null) {
|
||||||
|
nameController.text = selectedCollection!.name;
|
||||||
|
}
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text('Create Collection'),
|
title: EditDialogTitle(
|
||||||
|
dialogType: DialogType.collection,
|
||||||
|
onDeletePressed: onDeletePressed,
|
||||||
|
),
|
||||||
content: TextField(
|
content: TextField(
|
||||||
controller: nameController,
|
controller: nameController,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
@@ -23,17 +40,20 @@ class CreateBookmarkCollectionDialog extends StatelessWidget {
|
|||||||
FilteringTextInputFormatter.deny(RegExp(r'\s\s+')),
|
FilteringTextInputFormatter.deny(RegExp(r'\s\s+')),
|
||||||
],
|
],
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
|
// TODO: Localize
|
||||||
labelText: 'Collection Name',
|
labelText: 'Collection Name',
|
||||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
FloatingActionButton(
|
EditDialogActions(
|
||||||
onPressed: () {
|
onSavePressed: () {
|
||||||
onSavePressed(nameController.text);
|
final bookmark =
|
||||||
|
selectedCollection?.copyWith(name: nameController.text) ??
|
||||||
|
Collection(name: nameController.text);
|
||||||
|
onSavePressed(bookmark);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: Icon(Icons.save),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import 'package:flutter/services.dart';
|
|||||||
|
|
||||||
import '../model/bookmark.dart';
|
import '../model/bookmark.dart';
|
||||||
import '../model/maps_link_metadata.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 {
|
class CreateBookmarkDialog extends StatelessWidget {
|
||||||
const CreateBookmarkDialog({
|
const CreateBookmarkDialog({
|
||||||
@@ -13,6 +15,7 @@ class CreateBookmarkDialog extends StatelessWidget {
|
|||||||
this.selectedBookmark,
|
this.selectedBookmark,
|
||||||
this.selectedMapsLink,
|
this.selectedMapsLink,
|
||||||
});
|
});
|
||||||
|
|
||||||
final void Function(Bookmark bookmark)? onSavePressed;
|
final void Function(Bookmark bookmark)? onSavePressed;
|
||||||
final void Function()? onDeletePressed;
|
final void Function()? onDeletePressed;
|
||||||
final int collectionId;
|
final int collectionId;
|
||||||
@@ -36,25 +39,10 @@ class CreateBookmarkDialog extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Row(
|
title: EditDialogTitle(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
dialogType: DialogType.bookmark,
|
||||||
children: [
|
onDeletePressed: onDeletePressed,
|
||||||
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(
|
content: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -115,33 +103,23 @@ class CreateBookmarkDialog extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
Row(
|
EditDialogActions(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
onSavePressed: () {
|
||||||
children: [
|
final bookmark =
|
||||||
TextButton(
|
selectedBookmark?.copyWith(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
name: nameController.text,
|
||||||
child: Text('Cancel'),
|
link: linkController.text,
|
||||||
),
|
description: descriptionController.text,
|
||||||
FloatingActionButton(
|
) ??
|
||||||
onPressed: () {
|
Bookmark(
|
||||||
final bookmark =
|
collectionId: collectionId,
|
||||||
selectedBookmark?.copyWith(
|
name: nameController.text,
|
||||||
name: nameController.text,
|
link: linkController.text,
|
||||||
link: linkController.text,
|
description: descriptionController.text,
|
||||||
description: descriptionController.text,
|
);
|
||||||
) ??
|
onSavePressed?.call(bookmark);
|
||||||
Bookmark(
|
Navigator.of(context).pop();
|
||||||
collectionId: collectionId,
|
},
|
||||||
name: nameController.text,
|
|
||||||
link: linkController.text,
|
|
||||||
description: descriptionController.text,
|
|
||||||
);
|
|
||||||
onSavePressed?.call(bookmark);
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
child: Icon(Icons.save),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
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