65 lines
1.8 KiB
Dart
65 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../model/bookmark.dart';
|
|
import '../service/bookmarks_provider.dart';
|
|
import '../service/storage.dart';
|
|
import '../service/url_launcher.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> {
|
|
void onAddButtonPressed() => showDialog(
|
|
context: context,
|
|
builder: (context) => CreateBookmarkDialog(
|
|
collectionId: BookmarksProvider.selectedCollectionId!,
|
|
onSavePressed: onBookmarkSaved,
|
|
),
|
|
);
|
|
|
|
void onBookmarkSaved(Bookmark bookmark) {
|
|
Storage.addBookmark(bookmark);
|
|
setState(() {});
|
|
}
|
|
|
|
Widget bookmarkListBuilder(BuildContext context, Bookmark bookmark) {
|
|
return ListTile(
|
|
title: Text(bookmark.name),
|
|
onTap: () => launchUrlFromString(bookmark.link),
|
|
);
|
|
}
|
|
|
|
@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.builder(
|
|
itemBuilder: (context, index) =>
|
|
bookmarkListBuilder(context, bookmarks.elementAt(index)),
|
|
itemCount: bookmarks.length,
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: onAddButtonPressed,
|
|
child: Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
}
|