-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from osociety/external-link-warning
Warn before opening external links
- Loading branch information
Showing
5 changed files
with
54 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:url_launcher/url_launcher_string.dart'; | ||
import 'package:vernet/ui/external_link_dialog.dart'; | ||
|
||
Future<void> launchURL(String url) async => await canLaunchUrlString(url) | ||
? await launchUrlString(url) | ||
: throw 'Could not launch $url'; | ||
|
||
Future<void> launchURLWithWarning(BuildContext context, String url) { | ||
return showDialog( | ||
context: context, | ||
builder: (context) => ExternalLinkWarningDialog( | ||
link: url, | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:vernet/helper/utils_helper.dart'; | ||
|
||
class ExternalLinkWarningDialog extends StatelessWidget { | ||
const ExternalLinkWarningDialog({super.key, required this.link}); | ||
|
||
final String link; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AlertDialog( | ||
title: const Text("Confirm to open external link"), | ||
content: Text(link), | ||
actions: [ | ||
TextButton( | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
child: const Text('Cancel'), | ||
), | ||
TextButton.icon( | ||
onPressed: () { | ||
launchURL(link); | ||
}, | ||
icon: const Icon(Icons.link), | ||
label: const Text('Open Link'), | ||
), | ||
], | ||
); | ||
} | ||
} |