added error handling for invalid urls
This commit is contained in:
@@ -45,8 +45,9 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
selectedBookmark: selectedBookmark,
|
||||
onSavePressed: onBookmarkSaved,
|
||||
onDeletePressed: () {
|
||||
Storage.deleteBookmarkById(selectedBookmark.id);
|
||||
setState(() {});
|
||||
Storage.deleteBookmarkById(
|
||||
selectedBookmark.id,
|
||||
).whenComplete(() => setState(() {}));
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -60,7 +61,11 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
Widget bookmarksListItemBuilder(BuildContext context, Bookmark bookmark) {
|
||||
return ListTile(
|
||||
title: Text(bookmark.name),
|
||||
onTap: () => launchUrlFromString(bookmark.link),
|
||||
onTap: () => launchUrlFromString(bookmark.link).then((errorCode) {
|
||||
if (context.mounted && errorCode != UrlLaunchErrorCode.none) {
|
||||
return showUrlError(context, errorCode);
|
||||
}
|
||||
}),
|
||||
onLongPress: () => editBookmark(bookmark),
|
||||
);
|
||||
}
|
||||
@@ -104,4 +109,16 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showUrlError(BuildContext context, UrlLaunchErrorCode errorCode) {
|
||||
String errorText = '';
|
||||
if (errorCode == UrlLaunchErrorCode.couldNotLaunch) {
|
||||
errorText = 'Could not launch Url';
|
||||
} else {
|
||||
errorText = 'Invalid Url';
|
||||
}
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(errorText)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user