added dialog to collection page
This commit is contained in:
@@ -1,13 +1,20 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../model/bookmark.dart';
|
||||||
import '../service/bookmarks_provider.dart';
|
import '../service/bookmarks_provider.dart';
|
||||||
import '../service/storage.dart';
|
import '../service/storage.dart';
|
||||||
|
import '../widgets/create_bookmark_dialog.dart';
|
||||||
|
|
||||||
class CollectionPage extends StatelessWidget {
|
class CollectionPage extends StatefulWidget {
|
||||||
const CollectionPage({super.key});
|
const CollectionPage({super.key});
|
||||||
|
|
||||||
static const String routeName = '/bookmarks';
|
static const String routeName = '/bookmarks';
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CollectionPage> createState() => _CollectionPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CollectionPageState extends State<CollectionPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (BookmarksProvider.selectedCollectionId == null) {
|
if (BookmarksProvider.selectedCollectionId == null) {
|
||||||
@@ -17,19 +24,32 @@ class CollectionPage extends StatelessWidget {
|
|||||||
BookmarksProvider.selectedCollectionId!,
|
BookmarksProvider.selectedCollectionId!,
|
||||||
);
|
);
|
||||||
|
|
||||||
BookmarksProvider.selectedCollectionId == null;
|
final collection = Storage.loadCollections().firstWhere(
|
||||||
|
(c) => c.id == BookmarksProvider.selectedCollectionId,
|
||||||
|
);
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(title: Text(collection.name)),
|
||||||
title: Text(
|
|
||||||
Storage.loadCollections()
|
|
||||||
.firstWhere((c) => c.id == BookmarksProvider.selectedCollectionId)
|
|
||||||
.name,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
body: ListView(
|
body: ListView(
|
||||||
children: bookmarks.map((e) => ListTile(title: Text(e.name))).toList(),
|
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