Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix for preview problem #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/src/models/submission_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,24 +238,25 @@ class Submission extends SubmissionRef
/// eg: [{"gif": [SubmissionPreview]}]
///
/// Returns an empty List if the [Submission] does not have any image variations.
List<Map<String, SubmissionPreview>> get variants {
final List<Map<String?, SubmissionPreview>> previews =
<Map<String, SubmissionPreview>>[];
List<Map<String?, SubmissionPreview>> get variants {
final previews = <Map<String?, SubmissionPreview>>[];
if (!data!.containsKey('preview')) {
return previews as List<Map<String, SubmissionPreview>>;
return previews;
}
assert(data!['preview'].containsKey('images'));
final raw = data!['preview']['images'].cast<Map<String, dynamic>>();
final raw = data!['preview']['images'].cast<Map<String?, dynamic>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is the key here ever null?

for (final image in raw) {
if (image.containsKey('variants')) {
final _variants = image['variants'];
for (final variant in _variants.keys) {
print('variant_key: $variant');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These debug prints should be removed?

print('variant_key: ${_variants[variant]}');
previews
.add({variant: SubmissionPreview._fromMap(_variants[variant])});
}
}
}
return previews as List<Map<String, SubmissionPreview>>;
return previews;
}

/// Is this [Submission] pinned.
Expand Down Expand Up @@ -467,7 +468,7 @@ class SubmissionRef extends UserContent {
/// A representation of a submission's preview.
class SubmissionPreview {
/// The preview ID.
String get id => _id;
String? get id => _id;

/// A list of preview images scaled to various resolutions.
List<PreviewImage> get resolutions => _resolutions;
Expand All @@ -477,7 +478,7 @@ class SubmissionPreview {

late PreviewImage _source;
late List<PreviewImage> _resolutions;
late String _id;
String? _id;

SubmissionPreview._fromMap(Map<String, dynamic> map) {
final sourceMap = map['source'];
Expand Down