-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[url_launcher] Url launcher platform interface null safety #3142
[url_launcher] Url launcher platform interface null safety #3142
Conversation
93ff574
to
b7072f7
Compare
@@ -14,7 +13,7 @@ const MethodChannel _channel = MethodChannel('plugins.flutter.io/url_launcher'); | |||
/// An implementation of [UrlLauncherPlatform] that uses method channels. | |||
class MethodChannelUrlLauncher extends UrlLauncherPlatform { | |||
@override | |||
Future<bool> canLaunch(String url) { | |||
Future<bool?> canLaunch(String url) { |
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.
Returning a nullabe bool seems odd. Should it just be bool?
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 also felt the same, but since the documentation of the invokeMethod
explicitly mentioned the return value could be null
I decided for allowing null
.
I could of course check for null
on the Dart side and return false
if this is the case. Would this be the preferred solution? Enforcing non-null using the !
operator also doesn't feel correct since we have no real control on what's happening on the native side (or even inside the method channel logic).
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 think it is fair to do a check in invokeMethod
and return false
if the return value is null
.
However, if we do that, it might counts as a breaking change. @blasten Just wanted to make sure, we are going to introduce a major bump regardless of a public api breaking change or not, right?
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 have updated the code to match the above. The canLaunch
and launch
methods now return false
if the value from the native side is null
. I have also included additional unit test to test for these cases.
For now I left the version number as is until @blasten had a change to have a look at the situation.
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! Yeah, I have confirmed with @blasten offline, all the NNBD migrations are going to be a major bump, so making breaking changes in public API (like this one) is harmless.
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.
Does this mean this PR can be approved?
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.
all the NNBD migrations are going to be a major bump, so making breaking changes in public API (like this one) is harmless
This is the general guidance, and the default option. There are cases where doing a major bump is less desired.
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 think we reached a general consensus that we can leave the major bump, so I will leave it as is (see also feedback from Amir on CHANGELOG.md)
@@ -1,3 +1,7 @@ | |||
## 2.0.0-nullsafety |
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.
@amirh do you have any comment on this version bump?
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 think that for the null safety migration as we expect all platform implementations to get the same bump in close proximity it is reasonable to do a major bump on the platform interface.
|
||
if (methodCall.method == 'canLaunch') { | ||
if (methodCall.arguments['url'] == 'http://example.com/null') { | ||
return null; | ||
} | ||
} | ||
|
||
if (methodCall.method == 'launch') { | ||
if (methodCall.arguments['url'] == 'http://example.com/null') { | ||
return null; | ||
} | ||
} | ||
}); |
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.
nit: what about moving this code to the specific test where it's being used, or the setUp
function in the worst case? This way the test doesn't leak state, and it doesn't need log.clear();
in the tearDown
.
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.
The problem is that setting the mock method channel (using setMockMethodCallHandler
) has a global impact (this is how it is handled inside the MethodChannel
class). So if I am to update in the specific test it will affect all tests that are run after (or during, since tests can run in parallel) the specific test. Or am I missing something here?
For now I removed the above logic, as it turns out the method channel will automatically return null
if no return statement is specified, which is exactly the behavior needed by the tests. I did however added a return null;
statement to make the logic explicit instead of implicitly relying on the behavior of the implementation of the MethodChannel
class.
plugin_platform_interface: ^1.0.1 | ||
# TODO (mvanbeusekom): use pub.dev once 1.10.0-nullsafety released. | ||
plugin_platform_interface: | ||
git: |
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.
It looks like this would need to be a local path dependency: https://api.cirrus-ci.com/v1/task/4983717032624128/logs/main.log
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 have updated the code to use a local path dependency which has the same result unfortunately (https://api.cirrus-ci.com/v1/task/6308195557703680/logs/main.log).
We can only solve this be publishing the null safety version of the "plugin_platform_interface" package (or of course updating the publishable CI step, which is highly undesirable in my opinion).
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 see. I think we can skip this test for now. Feel free to revert it back to a git dependency. I think we will need that for some testing in the Flutter framework repo.
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, I have reverted back to the git dependency just to be sure.
@mvanbeusekom The analysis is failing due to an issue in the branch, but it was fixed by #3150. Therefore, you would also need to rebase, and add the |
BREAKING CHANGE: this will introduce null safety and thus updates the signature of several methods.
68a2dea
to
6e84ec9
Compare
It's missing the file: include: ../../../analysis_options.yaml
analyzer:
enable-experiment:
- non-nullable Otherwise, LGTM. The presubmits will be red until |
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
Indeed this file was supposed to be there and got removed locally when rebasing (my mistake), I just added the file again. Thanks for pointing it out. |
Description
Migration of "url_launcher_platform_interface" to null safety.
Note: I had to pin the "plugin_platform_interface" package to the git repo since version 1.1.0-nullsafety is not yet released (see companion PR #3115). I have decorated the line with a
# TODO (mvanbeusekom):
comment. Please let me know if I should solve this in a different way.Related Issues
flutter/flutter#66395
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?