2021-05-07 17:45:08 +00:00
|
|
|
import 'package:flutter_translate/flutter_translate.dart';
|
2021-02-02 14:33:23 +00:00
|
|
|
import 'package:logger/logger.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
|
|
|
|
import '../../core/services/dialog_service.dart';
|
|
|
|
import '../../core/util/logger.dart';
|
|
|
|
import '../../locator.dart';
|
|
|
|
|
|
|
|
class LinkService {
|
|
|
|
final Logger _logger = getLogger();
|
|
|
|
final DialogService _dialogService = locator<DialogService>();
|
|
|
|
|
|
|
|
Future open(String link) async {
|
2022-04-28 22:44:23 +00:00
|
|
|
Uri uri = Uri.parse(link);
|
|
|
|
|
|
|
|
if (await canLaunchUrl(uri)) {
|
|
|
|
await launchUrl(uri);
|
2021-02-02 14:33:23 +00:00
|
|
|
} else {
|
|
|
|
_logger.e('Could not launch link $link');
|
|
|
|
_dialogService.showDialog(
|
|
|
|
title: translate('link.dialog.title'),
|
2023-01-16 00:44:34 +00:00
|
|
|
description:
|
|
|
|
translate('link.dialog.description', args: {'link': link}));
|
2021-02-02 14:33:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|