Pubspec.fromMap constructor

Pubspec.fromMap(
  1. Map map
)

Implementation

factory Pubspec.fromMap(Map map) {
  Pubspec pubspec = Pubspec();
  Map<String, dynamic> others = {};
  map.forEach((key, value) {
    if (key == 'name') {
      pubspec = pubspec.copyWith(name: value);
    } else if (key == 'description') {
      pubspec = pubspec.copyWith(description: value);
    } else if (key == 'version') {
      pubspec = pubspec.copyWith(version: value);
    } else if (key == 'homepage') {
      pubspec = pubspec.copyWith(homepage: value);
    } else if (key == 'repository') {
      pubspec = pubspec.copyWith(repository: value);
    } else if (key == 'issue_tracker') {
      pubspec = pubspec.copyWith(issueTracker: value);
    } else if (key == 'documentation') {
      pubspec = pubspec.copyWith(documentation: value);
    } else if (key == 'publish_to') {
      pubspec = pubspec.copyWith(publishTo: value);
    } else if (key == 'environment') {
      pubspec = pubspec.copyWith(
          environment: Environment.fromMap(value.cast<String, dynamic>()));
    } else if (key == 'dependencies') {
      pubspec = pubspec.copyWith(
          dependencies: getDependencies(value.cast<String, dynamic>()));
    } else if (key == 'dev_dependencies') {
      pubspec = pubspec.copyWith(
          devDependencies: getDependencies(value.cast<String, dynamic>()));
    } else if (key == 'dependency_overrides') {
      pubspec = pubspec.copyWith(
          dependenciesOverride:
              getDependencies(value.cast<String, dynamic>()));
    } else if (key == 'flutter') {
      pubspec = pubspec.copyWith(
          flutter: FlutterData.fromMap(value.cast<String, dynamic>()));
    } else {
      if (value is Map || value is List) {
        others[key] = jsonDecode(jsonEncode(value));
      } else {
        others[key] = value;
      }
    }
  });
  pubspec = pubspec.copyWith(others: others);
  return pubspec;
}