-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[url_launcher] Migrates Link to null safety #3196
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
return pushRouteNameToFramework(context, routeName); | ||
await pushRouteNameToFramework(context, routeName); | ||
return; |
There was a problem hiding this comment.
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>?
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this 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, |
There was a problem hiding this comment.
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,
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return pushRouteNameToFramework(context, routeName); | ||
await pushRouteNameToFramework(context, routeName); | ||
return; |
There was a problem hiding this comment.
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!( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good suggestion! changed
Null safety migration for #3177