launchAction static method

Future<bool> launchAction(
  1. BuildContext context, {
  2. required LaunchType type,
  3. String? value,
  4. Uri? uri,
  5. Map<String, dynamic>? queryParameters,
  6. List<String>? allowedSchemes,
  7. LaunchMode mode = LaunchMode.platformDefault,
  8. LaunchOptions? options,
  9. CalendarEvent? calendarEvent,
  10. String? debounceKey,
})

Launches an action based on the specified LaunchType and parameters.

This method now supports various LaunchTypes, including social media with web fallbacks, calendar events, and file sharing.

type - The category of launch (e.g., website, phone, email, social media). value - The primary data string (e.g., URL, phone number, email address, social media handle). calendarEvent - Optional CalendarEvent object for calendar events. shareText - Text to share for LaunchType.share. shareSubject - Subject for sharing for LaunchType.share. allowedSchemes - An optional list of allowed URL schemes for security. mode - How the URL should be opened (e.g., in-app, system browser). debounceKey - Optional key to scope tap-debouncing per widget. Use a unique value (e.g., widget key or label) when multiple LaunchLink widgets are visible simultaneously so they debounce independently.

Returns true if successfully launched, false otherwise.

Implementation

static Future<bool> launchAction(
  BuildContext context, {
  required LaunchType type,
  String? value,
  Uri? uri,
  Map<String, dynamic>? queryParameters,
  List<String>? allowedSchemes,
  LaunchMode mode = LaunchMode.platformDefault,
  LaunchOptions? options,
  CalendarEvent? calendarEvent,
  String? debounceKey,
}) async {
  Uri resultUri = uri ?? Uri.tryParse(value ?? '') ?? Uri();
  final result = await _launchAction(
    context,
    type: type,
    value: value,
    uri: uri,
    queryParameters: queryParameters,
    allowedSchemes: allowedSchemes,
    mode: mode,
    calendarEvent: calendarEvent,
    debounceKey: debounceKey,
    options: options?.copyWith(
      onLaunchResult: (_, attemptedUri, success) {
        resultUri = attemptedUri;
      },
    ),
  );
  options?.onLaunchResult?.call(type, resultUri, result);
  return result;
}