Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an event stream to communicate with Android's native end #282

Merged
merged 12 commits into from
Oct 10, 2024

Conversation

JlUgia
Copy link
Member

@JlUgia JlUgia commented Oct 6, 2024

This change adds functionality to allow diverse communications channels between the platforms supported.

The existing relationship between Android's activity lifecycle and the Flutter engine is loose, and activity recreation events (for activity-aware plugins) re-creates the engine and all its bindings (e.g.: the data channel between the native and dart ends). There's been proposals to circumvent this limitation (see image_picker's proposal). This approach prefers to open up a channel between Flutter and the native end as soon as the widget is added to the tree, such that, if the main activity hosting the widget's action is destroyed, the new instance will pick up from where the last left.

This fixes #277, #274, #261, #206, and addresses #278 and #276.

The change includes:

  • Enable multiple channel implementations per platform
  • Use an event channel for Android
  • Update method channel name

JlUgia added 5 commits October 6, 2024 18:20
… an event stream to report payment status updates back to the widgets and those that operate synchronously

Update Google Pay button to use an event stream and avoid lifecycle issues
Copy link

@ViniciusDeep ViniciusDeep left a comment

Choose a reason for hiding this comment

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

I added some suggestion but in general LGTM!

Copy link
Member

@dmengelt dmengelt left a comment

Choose a reason for hiding this comment

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

LGTM

@stuartmorgan
Copy link
Collaborator

Is there a specific aspect here you wanted me to review? I'm not familiar with this codebase or its public API surface, so I can't provide much input on the overall design.

@JlUgia
Copy link
Member Author

JlUgia commented Oct 9, 2024

Is there a specific aspect here you wanted me to review? I'm not familiar with this codebase or its public API surface, so I can't provide much input on the overall design.

This addresses the issue we discussed about the native end of a plugin losing track of result objects (to report back to the dart end) when an activity on Android is recycled/destroyed before a result is returned. An event stream that subscribes at activity [re]creation time is present and ready to return results back to Flutter even in situations when the forefront activity is destroyed.

Concretely, it'd be valuable to get your thoughts on the solution proposed. Key files are:

  • pay_button.dart
  • google_pay_button.dart
  • apple_pay_button.dart
  • 3 .kt files under pay_android/

@ViniciusDeep
Copy link

By the way, @JlUgia, we performed some tests based on this branch on our side and resolved the issue you mentioned in the description.

LGTM!

@JlUgia JlUgia merged commit 55d340c into main Oct 10, 2024
1 check passed
@JlUgia JlUgia deleted the event_channel_android branch October 10, 2024 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when calling DataResult multiple times on the same instance
4 participants