58 lines
1.8 KiB
Dart
58 lines
1.8 KiB
Dart
import 'dart:convert';
|
|
import 'dart:developer';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:onufitness/environment/environment_config.dart';
|
|
import 'package:onufitness/utils/custom_sneakbar.dart';
|
|
import 'package:share_plus/share_plus.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
bool isTablet = 1.sw >= 600;
|
|
Future<void> launchAnylUrl(Uri url) async {
|
|
try {
|
|
if (!await launchUrl(url, mode: LaunchMode.externalApplication)) {
|
|
if (url.scheme == 'mailto') {
|
|
await Clipboard.setData(ClipboardData(text: url.path));
|
|
customSnackbar(
|
|
title: 'Email Copied',
|
|
message: 'Email address copied to clipboard',
|
|
);
|
|
} else {
|
|
throw Exception('Could not launch $url');
|
|
}
|
|
}
|
|
} catch (e) {
|
|
log('launchAnylUrl error: $e');
|
|
}
|
|
}
|
|
|
|
Future<void> postShareEnternalApp({
|
|
required BuildContext context,
|
|
required String postId,
|
|
required int tribeId,
|
|
}) async {
|
|
final encodedPostId = base64Url.encode(utf8.encode(postId));
|
|
final encodedTribeId = base64Url.encode(utf8.encode(tribeId.toString()));
|
|
final webUrl = EnvironmentConfigFactory.getConfig().webUrl;
|
|
final shareUrl =
|
|
tribeId != 0
|
|
? "https://$webUrl/tribe-post-link?tribeId=$encodedTribeId&postId=$encodedPostId"
|
|
: "https://$webUrl/post-link?postId=$encodedPostId";
|
|
|
|
await SharePlus.instance.share(
|
|
ShareParams(
|
|
text: shareUrl,
|
|
subject: 'Check out this post!',
|
|
sharePositionOrigin: Rect.fromCenter(
|
|
center: Offset(
|
|
MediaQuery.of(context).size.width / 2,
|
|
MediaQuery.of(context).size.height / 2,
|
|
),
|
|
width: 200,
|
|
height: 200,
|
|
),
|
|
),
|
|
);
|
|
}
|