isValid static method

bool isValid(
  1. Uri uri, {
  2. List<String>? allowedSchemes,
})

Validates if the provided uri is safe and meets scheme restrictions.

uri - The URI to validate. allowedSchemes - An optional whitelist of permitted schemes.

Returns true if the URI is non-empty and optionally matches allowed schemes.

Implementation

static bool isValid(Uri uri, {List<String>? allowedSchemes}) {
  final uriString = uri.toString();
  if (uriString.isEmpty) {
    developer.log(
      'Validation Error: URI is empty',
      name: 'Launchify',
      level: 900,
    );
    return false;
  }

  // Check if the scheme is allowed if a list is provided
  if (allowedSchemes != null && allowedSchemes.isNotEmpty) {
    if (!allowedSchemes.contains(uri.scheme)) {
      developer.log(
        'Validation Error: Scheme "${uri.scheme}" is not in the allowed list: $allowedSchemes',
        name: 'Launchify',
        level: 900,
      );
      return false;
    }
  }

  return true;
}