getImport function

String getImport (
  1. Element element
)

Implementation

String getImport(Element element) {
  // return early if source is null
  if (element.source == null) {
    return null;
  }

  // we don't need to import core dart types
  // or core flutter types
  if (!element.source.isInSystemLibrary) {
    final path = element.source.uri.toString();
    if (!path.startsWith('package:flutter/')) {
      return "'$path'";
    }
  }
  return null;
}