Skip to content

Null-safety badge on package listing #3626

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

Merged
merged 4 commits into from
May 20, 2020
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
5 changes: 5 additions & 0 deletions app/lib/frontend/request_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class RequestContext {
/// Whether experimental UI features are activated.
final bool isExperimental;

/// Whether we should display null-safety related data on the UI.
/// TODO: remove this field after launching null-safety support.
final bool isNullSafetyDisplayed;

/// Whether indexing of the content by robots should be blocked.
final bool blockRobots;

Expand All @@ -30,6 +34,7 @@ class RequestContext {
const RequestContext({
this.indentJson = false,
this.isExperimental = false,
this.isNullSafetyDisplayed = false,
this.blockRobots = true,
this.uiCacheEnabled = false,
});
Expand Down
2 changes: 2 additions & 0 deletions app/lib/frontend/templates/listing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ String renderPackageList(
'last_uploaded': view.shortUpdated,
'desc': view.ellipsizedDescription,
'is_flutter_favorite': view.tags.contains(PackageTags.isFlutterFavorite),
'is_null_safe': requestContext.isNullSafetyDisplayed &&
view.tags.contains(PackageVersionTags.isNullSafe),
'publisher_id': view.publisherId,
'publisher_url':
view.publisherId == null ? null : urls.publisherUrl(view.publisherId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,28 @@
{{/is_external}}
{{^is_external}}
<p class="packages-metadata">
v <a href="{{& url}}">{{version}}</a>
{{#show_prerelease_version}} / <a href="{{& prerelease_version_url}}">{{prerelease_version}}</a>{{/show_prerelease_version}}
• Updated: <span>{{last_uploaded}}</span>
<span class="packages-metadata-block">
v <a href="{{& url}}">{{version}}</a>
{{#show_prerelease_version}} / <a href="{{& prerelease_version_url}}">{{prerelease_version}}</a>{{/show_prerelease_version}}
• Updated: <span>{{last_uploaded}}</span>
</span>
{{#publisher_id}}
<img class="packages-vp-icon"
<span class="packages-metadata-block">
<img class="packages-vp-icon"
src="{{& static_assets.img__verified-publisher-icon_svg}}"
title="Published by a pub.dev verified publisher" />
<a href="/publishers/{{publisher_id}}">{{publisher_id}}</a>
<a href="/publishers/{{publisher_id}}">{{publisher_id}}</a>
</span>
{{/publisher_id}}
{{#is_flutter_favorite}}
<span class="package-badge">
<img class="package-badge-icon" src="{{static_assets.img__flutter-logo-32x32_png}}" />
Flutter Favorite
</span>
<span class="package-badge">
<img class="package-badge-icon" src="{{static_assets.img__flutter-logo-32x32_png}}" />
Flutter Favorite
</span>
{{/is_flutter_favorite}}
{{#is_null_safe}}
<span class="package-badge" title="Supports the null safety language feature.">Null safety</span>
{{/is_null_safe}}
</p>
{{/is_external}}
<div>{{& tags_html}}</div>
Expand Down
1 change: 1 addition & 0 deletions app/lib/shared/handler_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ shelf.Handler _requestContextWrapper(shelf.Handler handler) {
registerRequestContext(RequestContext(
indentJson: indentJson,
isExperimental: isExperimental,
isNullSafetyDisplayed: hasExperimentalCookie,
blockRobots: !enableRobots,
uiCacheEnabled: uiCacheEnabled,
));
Expand Down
6 changes: 6 additions & 0 deletions app/lib/shared/tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ abstract class PackageTags {
abstract class PackageVersionTags {
/// PackageVersion supports only legacy (Dart 1) SDK.
static const String isLegacy = 'is:legacy';

/// The PackageVersion is null-safe.
///
/// See definition at `_NullSafetyViolationFinder` in
/// https://github.com/dart-lang/pana/blob/master/lib/src/tag_detection.dart
static const String isNullSafe = 'is:null-safe';
}

/// Collection of SDK tags (with prefix and value).
Expand Down
7 changes: 5 additions & 2 deletions pkg/web_css/lib/src/_list_experimental.scss
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ body.experimental {
font-size: 12px;
}

.packages-metadata-block {
margin: 0 8px 0 0;
}

.package-badge {
display: inline-block;
background: white;
Expand All @@ -364,7 +368,7 @@ body.experimental {

font-size: 12px;
padding: 1px 6px;
margin: 0 12px;
margin: 0 8px 0 0;

.package-badge-icon {
max-width: 13px;
Expand All @@ -377,7 +381,6 @@ body.experimental {
.packages-vp-icon {
display: inline-block;
height: 14px;
margin-left: 4px;
position: relative;
top: 3px;
opacity: 0.5;
Expand Down