added launch in maps functionality
This commit is contained in:
@@ -3,6 +3,7 @@ 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 {
|
||||
@@ -15,31 +16,6 @@ class CollectionPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _CollectionPageState extends State<CollectionPage> {
|
||||
@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(
|
||||
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(
|
||||
@@ -52,4 +28,37 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
8
lib/service/url_launcher.dart
Normal file
8
lib/service/url_launcher.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
Future<void> launchUrlFromString(String url) async {
|
||||
final Uri uri = Uri.parse(url);
|
||||
if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) {
|
||||
throw Exception('Could not launch $url');
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ class CreateBookmarkDialog extends StatelessWidget {
|
||||
maxLength: 50,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'[a-zA-Z0-9äöüÄÖÜß\s]'),
|
||||
RegExp(r'[a-zA-Z0-9äöüÄÖÜß\s/:\.]'),
|
||||
),
|
||||
FilteringTextInputFormatter.deny(RegExp(r'\s\s+')),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user