Model.fromJson constructor
Creates a model instance from a JSON map.
Implementation
factory Model.fromJson(Map<String, dynamic> json) {
return Model(
id: json['id'] as int? ?? 0, // Default to 0 for tests
name: json['name'] as String? ?? 'Unknown model', // Default for tests
description: json['description'] as String?,
type: json['type'] != null
? ModelType.fromString(json['type'] as String)
: ModelType.other, // Default for tests
nsfw: json['nsfw'] as bool? ?? false, // Default for tests
poi: json['poi'] as bool? ?? false, // Default for tests
mode: json['mode'] as String?,
creator: json['creator'] != null
? CreatorInfo.fromJson(json['creator'] as Map<String, dynamic>)
: null,
tags:
(json['tags'] as List<dynamic>?)?.map((e) => e as String).toList() ??
[], // Default to empty list for tests
modelVersions: (json['modelVersions'] as List<dynamic>?)
?.map((e) => ModelVersion.fromJson(e as Map<String, dynamic>))
.toList() ??
[], // Default to empty list for tests
stats: json['stats'] != null
? ModelStats.fromJson(json['stats'] as Map<String, dynamic>)
: null,
imageUrl: json['imageUrl'] as String?,
createdAt: json['createdAt'] != null
? DateTime.parse(json['createdAt'] as String)
: null,
updatedAt: json['updatedAt'] != null
? DateTime.parse(json['updatedAt'] as String)
: null,
publishedAt: json['publishedAt'] != null
? DateTime.parse(json['publishedAt'] as String)
: null,
status: json['status'] != null
? ModelStatus.fromString(json['status'] as String)
: null,
earlyAccessEnabled: json['earlyAccessEnabled'] as bool?,
downloadUrl: json['downloadUrl'] as String?,
);
}