import 'package:share_plus/share_plus.dart'; import 'package:url_launcher/url_launcher.dart'; import '../appflow/model/location.dart'; class EnvironmentConnector { static Future openBrowser(Uri url) async { if (await canLaunchUrl(url)) { return await launchUrl(url); } return false; } static Future openMail(String mail) async { Uri uri = Uri(scheme: 'mailto', path: mail); openBrowser(uri); } static Future openPhone(String phoneNumber) async { Uri uri = Uri(scheme: 'tel', path: phoneNumber); openBrowser(uri); } static Future openFacebook(String id) async { Uri uri; uri = Uri(scheme: 'fb', path: 'profile', queryParameters: {'id': id}); Uri uriBackup = Uri.parse('https://www.facebook.com/$id'); //bool launched = await launchUrl(uri); //if (!launched) { await launchUrl(uriBackup); //} } static Future openInstagram(String id) async { Uri uri = Uri(scheme: 'instagram', path: id); Uri uriBackup = Uri.parse('https://www.instagram.com/$id'); if(!await openBrowser(uri)) { openBrowser(uriBackup); } } static Future openTwitter(String id) async { Uri uri = Uri(scheme: 'twitter', path: id); Uri uriBackup = Uri.parse('https://www.twitter.com/$id'); if(!await openBrowser(uri)) { openBrowser(uriBackup); } } static Future openMaps(LocationModel location) async { Uri? uri; Uri? uriBackup; if(location.latitude != null && location.longitude != null) { uri = Uri(scheme: 'geo', path: '${location.latitude},${location.longitude}'); } else if (location.address != null) { uri = Uri( scheme: 'maps', host: 'maps.google.com', path: '', queryParameters: { 'q': location.address, 'daddr': location.address, }, ); uriBackup = Uri.parse('https://www.google.com/maps/search/?api=1&query='+Uri.encodeFull(location.address!)); } if(!await openBrowser(uri!)) { openBrowser(uriBackup!); } } static void share(String text, {String? subject}) { Share.share(text, subject: subject); } }