I'd put that code in a separate `_undescore` function, and replace it with a regular expression replace like this:

```dart
String _underscore(String camelized) {
  return camelized.replaceAllMapped(new RegExp(r"([A-Z])"), (Match match) => "_${match.group(1).toLowerCase()}");
}
```