-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Add Flutter to existing apps explains how to use FlutterViewController (in Swift/Objective-C) or Flutter.createView (in Kotlin/Java) to create a Flutter view from an existing native app codebase. When creating a new view/screen, rarely is the user's activity from that screen going to be completely isolated from the rest of the app. Normally I would want to pass data to that screen via something like dependency injection, and then receive the results as data back in the native app codebase.
In Swift, when creating a new screen, I would normally provide it with the data it needs by passing an object into the initializer of a UIViewController subclass. FlutterViewController takes no arguments to replicate that pattern. To receive data back, I would set a delegate on the UIViewController subclass. The delegate would have one of its methods called when the screen is ready to be dismissed, and the results from that screen would be passed as arguments into the delegate method. The delegate would then be responsible for dismissing the screen.
From what I've found online, the only way to pass data between Flutter and a native codebase is by writing custom platform-specific code. So for my Flutter screen to receive data and send it back upon dismissal, I would have to manage separate asynchronous calls between Swift/Kotlin and Dart before the Flutter view is created, and before it is dismissed. This seems relatively cumbersome. Is there a better way?