resolve method

int? resolve({
  1. required int major,
  2. ManagedChannel channel = ManagedChannel.stable,
  3. String projectId = '',
  4. String? sdkVersion,
})

The version channel channel offers for major to project projectId on an SDK at sdkVersion: its pointer, raised by rollouts the project's bucket is in, then the newest version at or below that of the same major that isn't blocked and the SDK can run. A beta channel takes stable's too. Null when there is none.

Implementation

int? resolve({
  required int major,
  ManagedChannel channel = ManagedChannel.stable,
  String projectId = '',
  String? sdkVersion,
}) {
  final names = channel == ManagedChannel.beta ? const [ManagedChannel.stable, ManagedChannel.beta] : [channel];
  int? top;
  for (final c in names) {
    final p = channels[c]?[major];
    if (p != null && (top == null || p > top)) top = p;
  }
  final bucket = managedRolloutBucket(projectId, id);
  for (final r in rollouts) {
    if (!names.contains(r.channel) || versions[r.version]?.major != major) continue;
    if (bucket < r.percent && (top == null || r.version > top)) top = r.version;
  }
  if (top == null) return null;
  int? best;
  for (final e in versions.entries) {
    final n = e.key;
    if (n > top || e.value.major != major || blocked.contains(n)) continue;
    if (!sdkSatisfies(sdkVersion, e.value.minSdk)) continue;
    if (best == null || n > best) best = n;
  }
  return best;
}