extractFileKey static method
Extracts the Figma File Key from a URL or returns the key if it's already one.
Implementation
static String? extractFileKey(String input) {
if (input.isEmpty) return null;
// Regex to match figma.com/design/:key or figma.com/file/:key
final RegExp regExp = RegExp(r'(?:figma\.com\/(?:design|file)\/)([a-zA-Z0-9]+)');
final match = regExp.firstMatch(input);
if (match != null && match.groupCount >= 1) {
return match.group(1);
}
// If no match, assume the input itself might be the key (simple alphanumeric check)
if (RegExp(r'^[a-zA-Z0-9]+$').hasMatch(input)) {
return input;
}
return null;
}