fbmobile/lib/core/services/link_service.dart

27 lines
771 B
Dart
Raw Permalink Normal View History

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 {
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
}
}
}