symbolToKey static method

String symbolToKey(
  1. Symbol symbol
)

Converts a Symbol to a string key. The string key is derived from the symbol's name. If the symbol represents a private member (starts with '_'), it is prefixed with '#'. For example, Symbol('name') becomes 'name', and Symbol('_private') becomes '#_private'. symbol is the symbol to be converted. Returns the string representation of the symbol.

Implementation

static String symbolToKey(Symbol symbol) {
  var name = symbol.toString();
  var regExp = RegExp(r'\("(.+)"\)');
  var match = regExp.firstMatch(name)?.group(1);
  match = match != null ? "#$match" : null;
  return match ?? name;
}