tryDecode static method

ModelSource? tryDecode(
  1. String? encoded
)

Decode the string produced by encode. Returns null if the input is malformed or names an unknown kind (forward-compat).

Implementation

static ModelSource? tryDecode(String? encoded) {
  if (encoded == null) return null;
  final pipe = encoded.indexOf('|');
  if (pipe <= 0) return null;
  final kind = encoded.substring(0, pipe);
  final value = encoded.substring(pipe + 1);
  try {
    return switch (kind) {
      'network' => NetworkSource(value),
      'asset' => AssetSource(value),
      'bundled' => BundledSource(value),
      'file' => FileSource(value),
      _ => null,
    };
  } catch (_) {
    return null;
  }
}