Files
feeddeck/app/lib/utils/openurl.dart
Rico Berger 2d838240fd Improve openUrl Function (#262)
Instead of using an external browser on Android, we are now using the
In-App-Browser to open all urls. For all other platforms we keep the
current behaviour and just set the launch mode explicitly, for the case
the the default is changed in the used package.
2025-05-11 11:11:00 +02:00

33 lines
1.1 KiB
Dart

import 'dart:io' show Platform;
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:url_launcher/url_launcher.dart';
/// [openUrl] can be used to open the given [url] in the specified launch mode.
/// For iOS and Android we are using the In-App-Browser to launch the url, for
/// all other platforms we are using the external browser.
///
/// We do not have to check if the launch mode is really supported, because
/// `launchUrl` will fallback to a supported launch mode, when our preferred
/// mode is not supported.
Future<void> openUrl(String url) async {
var launchMode = LaunchMode.platformDefault;
if (kIsWeb) {
launchMode = LaunchMode.externalApplication;
} else if (Platform.isAndroid) {
launchMode = LaunchMode.inAppBrowserView;
} else if (Platform.isIOS) {
launchMode = LaunchMode.inAppBrowserView;
} else if (Platform.isMacOS) {
launchMode = LaunchMode.externalApplication;
} else if (Platform.isLinux) {
launchMode = LaunchMode.externalApplication;
} else if (Platform.isWindows) {
launchMode = LaunchMode.externalApplication;
}
await launchUrl(Uri.parse(url), mode: launchMode);
}