ModulePackage.fromValue constructor

ModulePackage.fromValue({
  1. required String name,
  2. required dynamic value,
})

Creates a module package from the provided name and configuration value.

The value may be either a package version or a map containing version and conditional configuration.

Implementation

factory ModulePackage.fromValue({
  required String name,
  required dynamic value,
}) {
  if (value is Map) {
    final map = Map<dynamic, dynamic>.from(value);

    return ModulePackage(
      name: name,
      version: map['version']?.toString() ?? 'any',
      when: map['when']?.toString(),
    );
  }

  return ModulePackage(
    name: name,
    version: value?.toString() ?? 'any',
  );
}