Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[url_launcher] Migrates Link to null safety #3196

Merged
merged 3 commits into from
Oct 23, 2020
Merged

Conversation

blasten
Copy link

@blasten blasten commented Oct 23, 2020

Null safety migration for #3177

@blasten blasten requested a review from mklim as a code owner October 23, 2020 20:39
@google-cla google-cla bot added the cla: yes label Oct 23, 2020
@blasten blasten requested review from mdebbar and ditman and removed request for mklim October 23, 2020 20:39
@blasten blasten changed the title Migrates Link to null safety [url_launcher] Migrates Link to null safety Oct 23, 2020
Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines -102 to +103
return pushRouteNameToFramework(context, routeName);
await pushRouteNameToFramework(context, routeName);
return;
Copy link
Member

Choose a reason for hiding this comment

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

Is this nnbd or just better practice? If pushRouteNameToFramework returns Future, why not return that from here? Is it because it's in another package and it's some Future<void>??

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering the same thing.

Copy link
Author

Choose a reason for hiding this comment

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

Otherwise, the analyzer complains:

A value of type 'ByteData' can't be returned from method '_followLink' because it has a return type of 'Future<void>'.dartreturn_of_invalid_type

Also, it doesn't seem like the intention is to return Future<ByteData>.

Copy link
Member

Choose a reason for hiding this comment

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

Ooooh good catch by the analyzer, I wonder how come that wasn't an error before nnbd!

Copy link
Contributor

Choose a reason for hiding this comment

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

Casting anything to void used to be fine. I'm not sure why it changed with nnbd.

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

Thanks for migrating this! I only have a few suggestions and questions, but nothing blocking.

}) : target = target ?? LinkTarget.defaultTarget,
Key? key,
required this.uri,
LinkTarget? target,
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about changing it to this:

LinkTarget target = LinkTarget.defaultTarget,

Copy link
Author

Choose a reason for hiding this comment

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

Done

}

Future<void> _followLink(BuildContext context) async {
if (!link.uri.hasScheme) {
if (link.uri == null || !link.uri!.hasScheme) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is not supposed to be called when uri is null. I think it's more appropriate to force it to be non-null:

if (!link.uri!.hasScheme) {

Copy link
Author

Choose a reason for hiding this comment

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

Done

Comment on lines -102 to +103
return pushRouteNameToFramework(context, routeName);
await pushRouteNameToFramework(context, routeName);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering the same thing.

final Completer<ByteData> completer = Completer<ByteData>();
if (debugForceRouter || _hasRouter(context)) {
SystemNavigator.routeInformationUpdated(location: routeName);
window.onPlatformMessage(
window.onPlatformMessage!(
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid repeatedly adding ! you can do:

final PlatformMessageCallback? onPlatformMessage = window.onPlatformMessage;
if (onPlatformMessage == null) {
  return Future<ByteData>.value(null);
}
// After this point, the analyzer knows that the local variable `onPlatformMessage` is
// not null, so there's no need to add ! anymore.

Copy link
Author

Choose a reason for hiding this comment

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

good suggestion! changed

@blasten blasten merged commit a26f14f into flutter:nnbd Oct 23, 2020
@blasten blasten deleted the link_nnbd branch October 23, 2020 21:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants