added abilty to edit and delete collections
This commit is contained in:
@@ -10,6 +10,7 @@ import 'collection_page.dart';
|
||||
|
||||
class CollectionsListPage extends StatefulWidget {
|
||||
const CollectionsListPage({super.key});
|
||||
|
||||
static const String routeName = '/collections';
|
||||
|
||||
@override
|
||||
@@ -17,11 +18,63 @@ class CollectionsListPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _CollectionsListPageState extends State<CollectionsListPage> {
|
||||
final collections = Storage.loadCollections();
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
final collections = Storage.loadCollections();
|
||||
final provider = context.watch<SharedLinkProvider>();
|
||||
addingNewBookmark = provider.currentMapsLinkMetadata != null;
|
||||
return Scaffold(
|
||||
@@ -40,58 +93,10 @@ class _CollectionsListPageState extends State<CollectionsListPage> {
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemBuilder: itemBuilder,
|
||||
itemBuilder: (context, index) =>
|
||||
collectionsListItemBuilder(context, collections.elementAt(index)),
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user