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

chore: NewsProvider - Allow the URL of a translated image to be null #5446

Merged
Merged
Show file tree
Hide file tree
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
14 changes: 10 additions & 4 deletions packages/smooth_app/lib/data_models/news_feed/newsfeed_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ class _TagLineItemNewsItem {
startDate: startDate,
endDate: endDate,
style: style?.toTagLineStyle(),
image: translation.image?.toTagLineImage(),
image: translation.image?.overridesContent == true
? translation.image?.toTagLineImage()
: null,
);
}

Expand Down Expand Up @@ -210,20 +212,22 @@ class _TagLineItemNewsTranslationDefault extends _TagLineItemNewsTranslation {
_TagLineItemNewsTranslationDefault.fromJson(Map<dynamic, dynamic> json)
: assert((json['title'] as String).isNotEmpty),
assert((json['message'] as String).isNotEmpty),
assert(json['image'] == null ||
((json['image'] as Map<String, dynamic>)['url'] as String)
.isNotEmpty),
super.fromJson(json);
}

class _TagLineNewsImage {
_TagLineNewsImage.fromJson(Map<dynamic, dynamic> json)
: assert((json['url'] as String).isNotEmpty),
assert(json['width'] == null ||
: assert(json['width'] == null ||
((json['width'] as num) >= 0.0 && (json['width'] as num) <= 1.0)),
assert(json['alt'] == null || (json['alt'] as String).isNotEmpty),
url = json['url'],
width = json['width'],
alt = json['alt'];

final String url;
final String? url;
final double? width;
final String? alt;

Expand All @@ -234,6 +238,8 @@ class _TagLineNewsImage {
alt: alt,
);
}

bool get overridesContent => url != null || width != null || alt != null;
}

class _TagLineNewsStyle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class AppNewsImage {
this.alt,
});

final String src;
final String? src;
final double? width;
final String? alt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class _TagLineContentBodyState extends State<_TagLineContentBody> {
}

Widget _image() {
if (widget.image!.src.endsWith('svg')) {
if (widget.image!.src?.endsWith('svg') == true) {
return SvgCache(
widget.image!.src,
semanticsLabel: widget.image!.alt,
Expand All @@ -323,7 +323,7 @@ class _TagLineContentBodyState extends State<_TagLineContentBody> {

return EMPTY_WIDGET;
},
widget.image!.src,
widget.image!.src ?? '-',
);
}
}
Expand Down