unhandledElement method

void unhandledElement(
  1. XmlStartElementEvent event
)

Prints an error for unhandled elements.

Will only print an error once for unhandled/unexpected elements, except for <style/>, <title/>, and <desc/> elements.

Implementation

void unhandledElement(XmlStartElementEvent event) {
  final String errorMessage =
      'unhandled element ${event.name}; Picture key: $_key';
  if (_warningsAsErrors) {
    // Throw error instead of log warning.
    throw UnimplementedError(errorMessage);
  }
  if (event.name == 'style') {
    FlutterError.reportError(FlutterErrorDetails(
      exception: UnimplementedError(
          'The <style> element is not implemented in this library.'),
      informationCollector: () => <DiagnosticsNode>[
        ErrorDescription(
            'Style elements are not supported by this library and the requested SVG may not '
            'render as intended.'),
        ErrorHint(
            'If possible, ensure the SVG uses inline styles and/or attributes (which are '
            'supported), or use a preprocessing utility such as svgcleaner to inline the '
            'styles for you.'),
        ErrorDescription(''),
        DiagnosticsProperty<String>('Picture key', _key),
      ],
      library: 'SVG',
      context: ErrorDescription('in parseSvgElement'),
    ));
  } else if (_unhandledElements.add(event.name)) {
    print(errorMessage);
  }
}