added workflow to add bookmark from share intent
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../model/bookmark.dart';
|
||||
import '../model/maps_link_metadata.dart';
|
||||
import '../service/bookmarks_provider.dart';
|
||||
import '../service/shared_link_provider.dart';
|
||||
import '../service/storage.dart';
|
||||
import '../service/url_launcher.dart';
|
||||
import '../widgets/create_bookmark_dialog.dart';
|
||||
@@ -16,17 +19,29 @@ class CollectionPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _CollectionPageState extends State<CollectionPage> {
|
||||
MapsLinkMetadata? selectedMapsLink;
|
||||
|
||||
void onAddButtonPressed() => showDialog(
|
||||
context: context,
|
||||
builder: (context) => CreateBookmarkDialog(
|
||||
collectionId: BookmarksProvider.selectedCollectionId!,
|
||||
onSavePressed: onBookmarkSaved,
|
||||
selectedMapsLink: selectedMapsLink,
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (selectedMapsLink != null) onAddButtonPressed();
|
||||
});
|
||||
}
|
||||
|
||||
void onBookmarkSaved(Bookmark bookmark) {
|
||||
Storage.addBookmark(bookmark);
|
||||
setState(() {});
|
||||
context.read<SharedLinkProvider>().removeCurrentMapsLink();
|
||||
}
|
||||
|
||||
Widget bookmarkListBuilder(BuildContext context, Bookmark bookmark) {
|
||||
@@ -38,6 +53,8 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SharedLinkProvider provider = context.watch<SharedLinkProvider>();
|
||||
selectedMapsLink = provider.currentMapsLinkMetadata;
|
||||
if (BookmarksProvider.selectedCollectionId == null) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
@@ -49,7 +66,18 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(collection.name)),
|
||||
appBar: AppBar(
|
||||
title: selectedMapsLink != null
|
||||
? Text('Add to ${collection.name}')
|
||||
: Text(collection.name),
|
||||
actions: [
|
||||
if (selectedMapsLink != null)
|
||||
TextButton(
|
||||
onPressed: () => provider.removeCurrentMapsLink(),
|
||||
child: Text('Cancel'),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemBuilder: (context, index) =>
|
||||
bookmarkListBuilder(context, bookmarks.elementAt(index)),
|
||||
@@ -57,7 +85,7 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: onAddButtonPressed,
|
||||
child: Icon(Icons.add),
|
||||
child: Icon(selectedMapsLink != null ? Icons.save : Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user