toList method

List<Object?>? toList()

Safe conversion to List<Object?>

Implementation

List<Object?>? toList() {
  final Object? self = this;
  if (self == null) return null;

  if (self is List<Object?>) return self;
  if (self is List) return self.cast<Object?>();
  if (self is Set) return self.cast<Object?>().toList();

  // Try JSON parsing
  if (self is String) {
    try {
      final Object? decoded = SafeParser.safeDecodeJson(self);
      if (decoded is List) {
        return decoded.cast<Object?>();
      }
    } catch (e) {
      // Ignore JSON parsing errors
    }
  }

  return null;
}