visualClickName function

String visualClickName(
  1. String? source
)

An icon name or an image / SVG path or URL → a name stem, RN's visualName: the file name without folders, query, extension or @2x, separators to spaces, then slugClickName. assets/icons/ic_home.png → ic_home, https://cdn.x/img/gold-coin.svg?v=3 → gold_coin, account circle → account_circle. Empty for a generic name (icon, logo, placeholder …) or one that slugs to nothing (a hash, digits).

Implementation

String visualClickName(String? source) {
  if (source == null || source.trim().isEmpty) return '';
  var file = source.trim().replaceFirst(_kUrlTail, '');
  final slash = file.lastIndexOf('/');
  if (slash >= 0) file = file.substring(slash + 1);
  try {
    file = Uri.decodeComponent(file);
  } catch (_) {}
  final dot = file.lastIndexOf('.');
  if (dot > 0) file = file.substring(0, dot);
  file = file.replaceFirst(_kDensitySuffix, '');
  final stem = slugClickName(file.replaceAll(_kNameSeparators, ' '));
  return _kGenericVisualNames.contains(stem) ? '' : stem;
}