initial
This commit is contained in:
75
lib/services/environment.dart
Normal file
75
lib/services/environment.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../appflow/model/location.dart';
|
||||
|
||||
class EnvironmentConnector {
|
||||
|
||||
static Future<bool> openBrowser(Uri url) async {
|
||||
if (await canLaunchUrl(url)) {
|
||||
return await launchUrl(url);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static Future<void> openMail(String mail) async {
|
||||
Uri uri = Uri(scheme: 'mailto', path: mail);
|
||||
openBrowser(uri);
|
||||
}
|
||||
|
||||
static Future<void> openPhone(String phoneNumber) async {
|
||||
Uri uri = Uri(scheme: 'tel', path: phoneNumber);
|
||||
openBrowser(uri);
|
||||
}
|
||||
|
||||
static Future<void> 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<void> 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<void> 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<void> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user