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

[url_launcher] Add url_launcher_platform_interface package #2217

Merged
merged 10 commits into from
Oct 22, 2019
Merged

[url_launcher] Add url_launcher_platform_interface package #2217

merged 10 commits into from
Oct 22, 2019

Conversation

harryterkelsen
Copy link
Contributor

Description

Adds urlLauncherPlatform which can be overridden to implement url_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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@harryterkelsen
Copy link
Contributor Author

Ping!

@amirh
Copy link
Contributor

amirh commented Oct 22, 2019

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)

@harryterkelsen
Copy link
Contributor Author

OK, then I think this will have to be done in 2 PRs. One to land package:url_launcher_platform_interface and publish it to pub, and then another to migrate package:url_launcher to use it.

@harryterkelsen harryterkelsen changed the title [url_launcher] Add overridable platform [url_launcher] Add url_launcher_platform_interface package Oct 22, 2019
@harryterkelsen
Copy link
Contributor Author

PTAL. I moved it to a separate package. Once this lands and we publish it, I will do a follow-up PR to migrate package:url_launcher to actually use it.

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, but I guess it's Amir's call!

flutter_test:
sdk: flutter
url_launcher:
path: ../url_launcher
Copy link
Member

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?

Copy link
Contributor

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_

Copy link
Contributor Author

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 {
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Contributor

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).

Copy link
Contributor Author

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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', () {
Copy link
Contributor

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).

Copy link
Contributor Author

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 {
Copy link
Contributor

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)

Copy link
Contributor Author

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
Copy link
Contributor

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)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@harryterkelsen
Copy link
Contributor Author

PTAL. FYI, for the platform interface, I am preferring having all the arguments be required, but maybe it would look nicer if they were @required named arguments instead? Look at the MethodChannelUrlLauncher test to see how it looks with all of the required arguments.

Copy link
Contributor

@amirh amirh left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@amirh
Copy link
Contributor

amirh commented Oct 22, 2019

PTAL. FYI, for the platform interface, I am preferring having all the arguments be required, but maybe it would look nicer if they were @required named arguments instead? Look at the MethodChannelUrlLauncher test to see how it looks with all of the required arguments.

Good point, I agree it call sites will be less confusing with @required named arguments.

@harryterkelsen harryterkelsen merged commit f04b3c8 into flutter:master Oct 22, 2019
mormih pushed a commit to mormih/plugins that referenced this pull request Nov 17, 2019
…#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
sungmin-park pushed a commit to sungmin-park/flutter-plugins that referenced this pull request Dec 17, 2019
…#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
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.

4 participants