parse<T> static method

PaywallLocalizedContent<T>? parse<T>(
  1. Object? source
)

Implementation

static PaywallLocalizedContent<T>? parse<T>(Object? source) {
  if (source is T) {
    return PaywallLocalizedContent(source);
  }
  if (source is! Map || source.isEmpty) {
    return PaywallLocalizedContent.none();
  }
  final en = source['en'];
  final entries = source.entries.map((e) {
    final key = e.key;
    if (key is! String || key.isEmpty) return null;
    final value = e.value;
    if (value is! T) return null;
    return MapEntry(key, value);
  }).whereType<MapEntry<String, T>>();
  if (en is! T && entries.isEmpty) return null;
  return PaywallLocalizedContent._(
    en is T ? en : null,
    Map.fromEntries(entries),
  );
}