Skip to content

Conversation

@cbracken
Copy link
Member

Adds a macOS implementation of the platform_channel example, demonstrating method channels and event channels with a battery power plugin.

Adds platform_channel_sample_test_macos macOS host test to verify the sample works.

Issue: #79204

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@cbracken cbracken requested a review from stuartmorgan-g March 21, 2023 18:26
@flutter-dashboard flutter-dashboard bot added d: examples Sample code and demos c: contributor-productivity Team-specific productivity, code health, technical debt. labels Mar 21, 2023
@cbracken cbracken force-pushed the macos-platform-channel branch 2 times, most recently from 9db4ce0 to f0c4e9a Compare March 21, 2023 18:46
@cbracken cbracken changed the title [macOS] Add macOS platform_channel test [macOS] Add platform_channel sample/test Mar 21, 2023
Copy link
Member

@loic-sharma loic-sharma 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 consider getting approval from someone with more Swift expertise.

@loic-sharma
Copy link
Member

Do you know why the platform_channel_swift example was split from platform_channel? Should we merge them? They seem to have similar battery logic: https://github.com/flutter/flutter/blob/master/examples/platform_channel_swift/ios/Runner/AppDelegate.swift

@cbracken
Copy link
Member Author

cbracken commented Mar 22, 2023

This code serves two primary purposes:

  • Demonstrate how to use platform channels
  • Test that they work

To the first point, having a separate Swift example made sense when the iOS default was Obj-C but we were migrating towards a Swift-based future. Now that the default for iOS plugins is Swift, it makes sense to simply replace the Obj-C example with the Swift code and delete the extra Swift example.

To the second point, the goal is an integration test verifying method and event channels; the language is irrelevant, so Swift-only should be sufficient.

/cc @jmagman for thoughts on that end. If you think it makes sense to keep an Obj-C version around, I'd suggest the Swift implementation be moved to the main platform_channel example and a separate iOS-only Obj-C example created, but to be honest I don't think it adds much value; most Obj-C developers will be able to translate the example themselves.

@cbracken cbracken force-pushed the macos-platform-channel branch from 01b28ae to a8669a6 Compare March 22, 2023 23:03
Copy link
Contributor

@yaakovschectman yaakovschectman 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 am not very familiar with Swift or MacOS

@stuartmorgan-g
Copy link
Contributor

stuartmorgan-g commented Mar 23, 2023

If you think it makes sense to keep an Obj-C version around, I'd suggest the Swift implementation be moved to the main platform_channel example and a separate iOS-only Obj-C example created

+1 to doing this if we keep both. (I should probably do the same with Android, moving Java out and making the primary example Kotlin.)

but to be honest I don't think it adds much value; most Obj-C developers will be able to translate the example themselves.

We also link to this as the runnable version of https://docs.flutter.dev/development/platform-integration/platform-channels#example (updating that page was the initial motivation for me wanting the macOS version of this code). If we remove the Obj-C example here we'll need to at least update the text in that info box; we could also re-evaluate whether we still also want the Obj-C example on that page.

Adds a macOS implementation of the platform_channel example,
demonstrating method channels and event channels with a battery power
plugin.

Adds platform_channel_sample_test_macos macOS host test to verify the
sample works.

Issue: flutter#79204
@cbracken cbracken force-pushed the macos-platform-channel branch from a8669a6 to 1ed8098 Compare March 23, 2023 16:56
For consistency with rest of examples.
@cbracken cbracken force-pushed the macos-platform-channel branch from 1ed8098 to fd0591b Compare March 23, 2023 16:59
@cbracken cbracken merged commit 674ff15 into flutter:master Mar 23, 2023
@cbracken cbracken deleted the macos-platform-channel branch March 23, 2023 18:56
@jmagman
Copy link
Member

jmagman commented Mar 23, 2023

@hellohuanlin would you mind reviewing this post-merge? @cbracken can follow up with changes you suggest.

tarrinneal pushed a commit to flutter/packages that referenced this pull request Mar 24, 2023
* cbdee52 Roll Flutter Engine from 59acb5362098 to 12c822327825 (3 revisions) (flutter/flutter#123330)

* 897e3db Inject the gstatic CanvasKit CDN URL by default in `flutter build web` (flutter/flutter#122772)

* 5a36bdd Stop serving Observatory by default (flutter/flutter#122419)

* b212e7b implement Iterator and Comparable instead of extending them (flutter/flutter#123282)

* af6029c c0fbe5a53 Roll Dart SDK from 9256fffbd5af to e8e045620234 (1 revision) (flutter/engine#40561) (flutter/flutter#123336)

* 9dec4fb FIX: NavigationDrawer hover/focus/pressed does not use indicatorShape (flutter/flutter#123325)

* 4907464 20ab040cd Roll Skia from ce5ff5cc03ce to c42320d53714 (2 revisions) (flutter/engine#40565) (flutter/flutter#123340)

* 28d40a4 Roll Packages from 75491e9 to 0826798 (5 revisions) (flutter/flutter#123342)

* 674ff15 [macOS] Add platform_channel sample/test (flutter/flutter#123141)

* 7b7af9f roll packages (flutter/flutter#123339)

* 3179875 replace some ._() constructors with class modifiers (flutter/flutter#122765)

* 7f41ab2 Fix (insert|move|remove)RenderObjectChild methods in base class (flutter/flutter#123276)

* fccca49 Refactor buildOverscrollIndicator (flutter/flutter#123246)

* 11bbce1 6b0933e74 [web] Add `dart:js_interop` to `_embedder.yaml`. (flutter/engine#40545) (flutter/flutter#123347)

* 716d252 Remove prefer_const_constructors ignores (flutter/flutter#123284)

* 100cf21 Prefer enum over class. (flutter/flutter#123312)

* 5ef9b84 Expose toggle to textfield's opacity animation. (flutter/flutter#122474)

* d79f3aa Roll Flutter Engine from 6b0933e74965 to bdce896fb64f (2 revisions) (flutter/flutter#123351)
Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

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

Just a few comments. Let me know if any questions and I'm more than happy to assist (anything Swift related is my favorite!)

Some comments might be outdated since you may have fixed it in separate PRs

stuartmorgan-g added a commit to flutter/website that referenced this pull request Apr 5, 2023
This adds a macOS section to the example implementation instructions, following the same structure as the existing examples, and using the code from flutter/flutter#123141

This is the macOS equivalent of #7328 and #8127

Fixes flutter/flutter#79204
sfshaza2 pushed a commit to flutter/website that referenced this pull request Apr 5, 2023
This adds a macOS section to the example implementation instructions,
following the same structure as the existing examples, and using the
code from flutter/flutter#123141

This is the macOS equivalent of
#7328 and
#8127

Fixes flutter/flutter#79204

## Presubmit checklist
- [x] This PR doesn’t contain automatically generated corrections
(Grammarly or similar).
- [x] This PR follows the [Google Developer Documentation Style
Guidelines](https://developers.google.com/style) — for example, it
doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person).
- [x] This PR uses [semantic line
breaks](https://github.com/dart-lang/site-shared/blob/master/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks)
of 80 characters or fewer.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
nploi pushed a commit to nploi/packages that referenced this pull request Jul 16, 2023
)

* cbdee52 Roll Flutter Engine from 59acb5362098 to 12c822327825 (3 revisions) (flutter/flutter#123330)

* 897e3db Inject the gstatic CanvasKit CDN URL by default in `flutter build web` (flutter/flutter#122772)

* 5a36bdd Stop serving Observatory by default (flutter/flutter#122419)

* b212e7b implement Iterator and Comparable instead of extending them (flutter/flutter#123282)

* af6029c c0fbe5a53 Roll Dart SDK from 9256fffbd5af to e8e045620234 (1 revision) (flutter/engine#40561) (flutter/flutter#123336)

* 9dec4fb FIX: NavigationDrawer hover/focus/pressed does not use indicatorShape (flutter/flutter#123325)

* 4907464 20ab040cd Roll Skia from ce5ff5cc03ce to c42320d53714 (2 revisions) (flutter/engine#40565) (flutter/flutter#123340)

* 28d40a4 Roll Packages from 75491e9 to 0826798 (5 revisions) (flutter/flutter#123342)

* 674ff15 [macOS] Add platform_channel sample/test (flutter/flutter#123141)

* 7b7af9f roll packages (flutter/flutter#123339)

* 3179875 replace some ._() constructors with class modifiers (flutter/flutter#122765)

* 7f41ab2 Fix (insert|move|remove)RenderObjectChild methods in base class (flutter/flutter#123276)

* fccca49 Refactor buildOverscrollIndicator (flutter/flutter#123246)

* 11bbce1 6b0933e74 [web] Add `dart:js_interop` to `_embedder.yaml`. (flutter/engine#40545) (flutter/flutter#123347)

* 716d252 Remove prefer_const_constructors ignores (flutter/flutter#123284)

* 100cf21 Prefer enum over class. (flutter/flutter#123312)

* 5ef9b84 Expose toggle to textfield's opacity animation. (flutter/flutter#122474)

* d79f3aa Roll Flutter Engine from 6b0933e74965 to bdce896fb64f (2 revisions) (flutter/flutter#123351)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. d: examples Sample code and demos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants