Files
maps_bookmarks/lib/pages/collections_page.dart
2025-11-02 16:14:10 +01:00

73 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
import '../model/collection.dart';
import '../service/bookmarks_provider.dart';
import '../service/share_intent_service.dart';
import '../service/storage.dart';
import '../widgets/create_bookmark_collection_dialog.dart';
import 'bookmarks_page.dart';
class CollectionsPage extends StatefulWidget {
const CollectionsPage({super.key});
static const String routeName = '/collections';
@override
State<CollectionsPage> createState() => _CollectionsPageState();
}
class _CollectionsPageState extends State<CollectionsPage> {
final collections = Storage.loadCollections();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
floatingActionButton: FloatingActionButton(
onPressed: onAddButtonPressed,
child: Icon(Icons.add),
),
body: ListView.builder(
itemBuilder: itemBuilder,
itemCount: collections.length,
),
);
}
void onAddButtonPressed() => showDialog(
context: context,
builder: (context) =>
CreateBookmarkCollectionDialog(onSavePressed: onCollectionSaved),
);
void onCollectionSaved(String name) {
collections.add(Collection(name: name));
setState(() {});
Storage.saveCollections(collections);
}
Widget itemBuilder(BuildContext context, int index) {
final collection = collections.elementAt(index);
return ListTile(
title: Text(collection.name),
onTap: () {
BookmarksProvider.selectedCollectionId = collection.id;
Navigator.pushNamed(context, BookmarksPage.routeName);
},
);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
// Check if we received shared data
final metadata =
ModalRoute.of(context)?.settings.arguments as MapsLinkMetadata?;
if (metadata != null) {
// Handle the shared link
WidgetsBinding.instance.addPostFrameCallback((_) {
// _showSaveBookmarkDialog(metadata);
});
}
}
}