Files
maps_bookmarks/lib/pages/collection_page.dart
2025-12-09 12:56:53 +01:00

56 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
import '../model/bookmark.dart';
import '../service/bookmarks_provider.dart';
import '../service/storage.dart';
import '../widgets/create_bookmark_dialog.dart';
class CollectionPage extends StatefulWidget {
const CollectionPage({super.key});
static const String routeName = '/bookmarks';
@override
State<CollectionPage> createState() => _CollectionPageState();
}
class _CollectionPageState extends State<CollectionPage> {
@override
Widget build(BuildContext context) {
if (BookmarksProvider.selectedCollectionId == null) {
Navigator.of(context).pop();
}
final bookmarks = Storage.loadBookmarksForCollection(
BookmarksProvider.selectedCollectionId!,
);
final collection = Storage.loadCollections().firstWhere(
(c) => c.id == BookmarksProvider.selectedCollectionId,
);
return Scaffold(
appBar: AppBar(title: Text(collection.name)),
body: ListView(
children: bookmarks.map((e) => ListTile(title: Text(e.name))).toList(),
),
floatingActionButton: FloatingActionButton(
onPressed: onAddButtonPressed,
child: Icon(Icons.add),
),
);
}
void onAddButtonPressed() => showDialog(
context: context,
builder: (context) => CreateBookmarkDialog(
collectionId: BookmarksProvider.selectedCollectionId!,
onSavePressed: onBookmarkSaved,
),
);
void onBookmarkSaved(Bookmark bookmark) {
Storage.addBookmark(bookmark);
setState(() {});
}
}