-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[url_launcher] Add url_launcher_platform_interface
package
#2217
[url_launcher] Add url_launcher_platform_interface
package
#2217
Conversation
Ping! |
The platform interface should go in a separate package, otherwise we will have a dependency cycle between url_launcher_web and url_launcher (once the web implementation is endorsed) |
OK, then I think this will have to be done in 2 PRs. One to land |
url_launcher_platform_interface
package
PTAL. I moved it to a separate package. Once this lands and we publish it, I will do a follow-up PR to migrate |
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, but I guess it's Amir's call!
flutter_test: | ||
sdk: flutter | ||
url_launcher: | ||
path: ../url_launcher |
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.
Should this be a dependency on a published version of the plugin, instead of a path?
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 shouldn't have this dependency here at all (see my comment on the test_
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.
Removed dependency
}, skip: true); | ||
} | ||
|
||
class MockUrlLauncherPlatform extends UrlLauncherPlatform { |
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.
Maybe extract this to its own test/mocks/mock_url_launcher_platform.dart file?
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.
Removed this test. Just testing the MethodChannel
implementation now
# Usage | ||
|
||
To implement a new platform-specific implementation of `url_launcher`, you can | ||
either implement the method channel calls (specified in |
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 would not mentioned, I don't think we'll treat that as an officially supported path (e.g we may decide to change the method channel protocol or mechanism at some point).
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.
/// | ||
/// For documentation on the other arguments, see the `launch` documentation | ||
/// in `package:url_launcher/url_launcher.dart`. | ||
Future<bool> launch( |
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.
These should have default implementations that throw unimplemented.
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.
import 'dart:async'; | ||
|
||
/// The interface that implementations of url_launcher must implement. | ||
abstract class UrlLauncherPlatform { |
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.
Add to the class doc that implementers should extend this class and not implement it, otherwise we won't be able to add new methods.
See similar comment on webview:
/// Platform implementations that live in a separate package should extend this class rather than |
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.
|
||
// TODO(hterkelsen): Re-enable this test once we land the corresponding | ||
// change in package:url_launcher | ||
group('UrlLauncher with mock platform', () { |
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 is testing the app-facing plugin and not the platform interface. Not sure there's anything to test for UrlLauncherPlatform
.
I think it will make sense for the tests in this package to be testing the platform channel implementation (with a mock method handler).
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.
Added a test for MethodChannelUrlLauncher
import 'dart:async'; | ||
|
||
/// The interface that implementations of url_launcher must implement. | ||
abstract class UrlLauncherPlatform { |
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 static platform field should be on this class and not on the app-facing plugin (so that platform implementations don't need to depend on the app-facing package)
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.
description: A common platform interface for the url_launcher plugin. | ||
author: Flutter Team <flutter-dev@googlegroups.com> | ||
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_platform_interface | ||
version: 0.1.0 |
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.
Let's add a comment reminding that is really bad to make a breaking change to this package, and that it's usually better to compromise on a less clean platform interface API. You can refer to the relevant section here: https://docs.google.com/document/d/1LD7QjmzJZLCopUrFAAE98wOUQpjmguyGTN2wd_89Srs/edit#heading=h.xabf9lffxrkb (I'll add a go link for that bookmark)
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.
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 (in the README)
description: A common platform interface for the url_launcher plugin. | ||
author: Flutter Team <flutter-dev@googlegroups.com> | ||
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_platform_interface | ||
version: 0.1.0 |
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.
For that same reason, I'm thinking to start this package at 1.0.0
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.
PTAL. FYI, for the platform interface, I am preferring having all the arguments be required, but maybe it would look nicer if they were |
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! (modulo nit)
description: A common platform interface for the url_launcher plugin. | ||
author: Flutter Team <flutter-dev@googlegroups.com> | ||
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_platform_interface | ||
version: 1.0.0 |
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'd keep the comment here as well, I feel like ongoing maintainers are less likely to page in the README before publishing, but they will visit this line for sure if they want to bump the major version.
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.
Good point, I agree it call sites will be less confusing with |
…#2217) * [url_launcher] Add overridable platform * Fix analyzer lints * Run dartfmt * Add a url_launcher_platform_interface package * Disable tests temporarily * Add license header * Fix typo in test * Add LICENSE file * Respond to review comments * Respond to review comments
…#2217) * [url_launcher] Add overridable platform * Fix analyzer lints * Run dartfmt * Add a url_launcher_platform_interface package * Disable tests temporarily * Add license header * Fix typo in test * Add LICENSE file * Respond to review comments * Respond to review comments
Description
Adds
urlLauncherPlatform
which can be overridden to implementurl_launcher
on other platforms (which may not want to use MethodChannels).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?