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 createState() => _CollectionPageState(); } class _CollectionPageState extends State { @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(() {}); } }