UpdatePolicy.fromJson constructor

UpdatePolicy.fromJson(
  1. Map<String, dynamic> json
)

Builds a policy from a remote configuration map, e.g.:

{
  "latest": {"stable": "2.1.0", "beta": "2.2.0-beta.1"},
  "minimum": {"stable": "1.9.0"}
}

Implementation

factory UpdatePolicy.fromJson(Map<String, dynamic> json) {
  final latestMap = (json['latest'] as Map<String, dynamic>?) ?? const {};
  final minimumMap = (json['minimum'] as Map<String, dynamic>?) ?? const {};
  final minimumForStable = minimumMap['stable'] as String?;
  return UpdatePolicy(
    minimumVersion: minimumForStable == null
        ? null
        : PrismVersion.parse(minimumForStable),
    channels: {
      for (final channel in UpdateChannel.values)
        if (latestMap.containsKey(channel.name)) channel,
    },
  );
}