Skip to content
This repository was archived by the owner on Nov 20, 2022. It is now read-only.

Commit a5546d2

Browse files
committed
✨ Improve launch url method
1 parent d96fbf8 commit a5546d2

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

lib/pages/login.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ class _LoginPageState extends State<LoginPage> {
137137
MaterialStateProperty.all<Color>(
138138
Colors.blueAccent)),
139139
child: new Text("Envoyer un mail"),
140-
onPressed: () {
141-
launchURL("mailto:androz2091@gmail.com?subject=Problème de connexion à Notifications pour Pronote&body=Bonjour, je rencontre des difficultés pour me connecter à l'application.\n\nMéthode d'authentification:\n" +
140+
onPressed: () async {
141+
final Uri emailParams = Uri(
142+
scheme: 'mailto',
143+
path: 'androz2091@gmail.com',
144+
query: 'subject=Problème de connexion à Notifications pour Pronote&body=Bonjour, je rencontre des difficultés pour me connecter à l\'application.\n\nMéthode d\'authentification:\n' +
142145
(_useGeolocation
143146
? 'Géolocalisation (' +
144147
(_establishmentsLoaded
@@ -149,7 +152,11 @@ class _LoginPageState extends State<LoginPage> {
149152
: 'URL personnalisée (' +
150153
(_pronoteURL ?? 'aucune URL') +
151154
')') +
152-
"\n\nSerait-il possible de m'aider ?\n\nCordialement,\nYour Name Here");
155+
'\n\nSerait-il possible de m\'aider ?\n\nCordialement,\nYour Name Here'
156+
);
157+
final url = emailParams.toString();
158+
final launched = await launchURL(url);
159+
if (!launched) showInfoDialog(context, title: 'Erreur', content: 'Impossible d\'ouvrir l\'application mail automatiquement...');
153160
})
154161
]);
155162
} else {

lib/url.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import 'package:url_launcher/url_launcher.dart';
22

3-
void launchURL(_url) async =>
4-
await canLaunch(_url) ? await launch(_url) : throw 'Could not launch $_url';
3+
Future<bool> launchURL(_url) async {
4+
final canLaunchURL = await canLaunch(_url);
5+
if (canLaunchURL) launch(_url);
6+
return canLaunchURL;
7+
}

lib/widgets/dialogs.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ void showAboutAppDialog(BuildContext context) {
3333
backgroundColor:
3434
MaterialStateProperty.all<Color>(Colors.deepOrangeAccent)),
3535
child: new Text("Faire un don"),
36-
onPressed: () {
37-
launchURL('https://paypal.me/andr0z');
36+
onPressed: () async {
37+
final launched = await launchURL('https://paypal.me/andr0z');
38+
if (!launched) {
39+
showInfoDialog(context, title: 'Erreur', content: 'Impossible d\'ouvrir le lien automatiquement. Utilisez https://paypal.me/andr0z pour nous soutenir !');
40+
}
3841
},
3942
)
4043
]);

0 commit comments

Comments
 (0)