extractStrings method

List<ExtractedString> extractStrings(
  1. String source
)

Implementation

List<ExtractedString> extractStrings(String source) {
  final result = <ExtractedString>[];
  var parseResult = parseString(content: source, throwIfDiagnostics: false);
  var unit = parseResult.unit;
  // If parsing produced top-level errors (snippet rather than full file), try wrapping with a main() to parse
  if (parseResult.errors.isNotEmpty) {
    final wrapped = 'void main() { $source }';
    parseResult = parseString(content: wrapped, throwIfDiagnostics: false);
    unit = parseResult.unit;
  }

  unit.accept(_ASTVisitor(result, widgetWhitelist));

  return result;
}