parseDartBinVersionOutput function

Version parseDartBinVersionOutput(
  1. String text
)

Parse version from 'dart --version' output.

Implementation

Version parseDartBinVersionOutput(String text) {
  var output = LineSplitter.split(text)
      .join(' ')
      .split(' ')
      .map((word) => word?.trim())
      .where((word) => word?.isNotEmpty ?? false);
  var foundDart = false;
  try {
    for (var word in output) {
      if (foundDart) {
        try {
          var version = Version.parse(word);
          if (version != null) {
            return version;
          }
        } catch (_) {}
      }
      if (word.toLowerCase().contains('dart')) {
        foundDart = true;
      }
    }
  } catch (_) {}
  return null;
}