import 'package:url_launcher/url_launcher.dart'; Future launchUrlFromString(String url) async { final Uri? uri = Uri.tryParse(url); final isValid = uri != null && uri.hasAbsolutePath && uri.scheme.startsWith('http'); if (!isValid) return UrlLaunchErrorCode.invalidUrl; if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) { return UrlLaunchErrorCode.couldNotLaunch; } return UrlLaunchErrorCode.none; } enum UrlLaunchErrorCode { none, couldNotLaunch, invalidUrl }