mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
initialized Application theme
This commit is contained in:
76
lib/utils/helpers/url_launcher.dart
Normal file
76
lib/utils/helpers/url_launcher.dart
Normal file
@ -0,0 +1,76 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class URLLauncher {
|
||||
static Future<void> sendWhatsapp(
|
||||
{String phoneNumber = '971581497062',
|
||||
String text = 'Hi%2C%20I%20would%20like%20to',
|
||||
String from = ''}) async {
|
||||
Uri launchUri;
|
||||
launchUri = Uri.parse("whatsapp://send?phone=%2B$phoneNumber&text=$text");
|
||||
// Launch the App
|
||||
try {
|
||||
// SegmentEvents.sendTrackEvent(SegmentEventModel(
|
||||
// eventName: 'Whatsapp opened', properties: {'From': from}));
|
||||
//
|
||||
// if (await canLaunchUrl(launchUri) == false) {
|
||||
// CustomSnackBar.displaySnackBar('Could not open whatsapp');
|
||||
// return;
|
||||
// }
|
||||
if (Platform.isAndroid) {
|
||||
await launch(
|
||||
launchUri.toString(),
|
||||
);
|
||||
} else {
|
||||
await launchUrl(
|
||||
launchUri,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
// CustomSnackBar.displaySnackBar('Could not open whatsapp');
|
||||
throw 'Could not launch $phoneNumber';
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> sendEmail(
|
||||
{required String email, String subject = '', body = ''}) async {
|
||||
String? encodeQueryParameters(Map<String, String> params) {
|
||||
return params.entries
|
||||
.map((MapEntry<String, String> e) =>
|
||||
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
|
||||
.join('&');
|
||||
}
|
||||
|
||||
final emailLaunchUri = Uri(
|
||||
scheme: 'mailto',
|
||||
path: email,
|
||||
query: encodeQueryParameters(<String, String>{
|
||||
subject: body,
|
||||
}),
|
||||
);
|
||||
try {
|
||||
bool canLaunch = await canLaunchUrl(emailLaunchUri);
|
||||
if (canLaunch) {
|
||||
await launchUrl(emailLaunchUri);
|
||||
}
|
||||
} catch (err) {
|
||||
throw 'Could not launch $emailLaunchUri';
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> launch(String url) async {
|
||||
Uri parsedUrl = Uri.parse(url);
|
||||
try {
|
||||
bool canLaunch = await canLaunchUrl(parsedUrl);
|
||||
if (canLaunch) {
|
||||
await launchUrl(
|
||||
parsedUrl,
|
||||
// mode: LaunchMode.externalApplication,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
throw 'Url launcher error: ${err.toString()}';
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user