added dialog to collection page
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
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 StatelessWidget {
|
||||
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) {
|
||||
@@ -17,19 +24,32 @@ class CollectionPage extends StatelessWidget {
|
||||
BookmarksProvider.selectedCollectionId!,
|
||||
);
|
||||
|
||||
BookmarksProvider.selectedCollectionId == null;
|
||||
final collection = Storage.loadCollections().firstWhere(
|
||||
(c) => c.id == BookmarksProvider.selectedCollectionId,
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
Storage.loadCollections()
|
||||
.firstWhere((c) => c.id == BookmarksProvider.selectedCollectionId)
|
||||
.name,
|
||||
),
|
||||
),
|
||||
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(() {});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user