<p dir="auto"><a href="https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps">Add Flutter to existing apps</a> explains how to use <code class="notranslate">FlutterViewController</code> (in Swift/Objective-C) or <code class="notranslate">Flutter.createView</code> (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.</p>
<p dir="auto">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 <code class="notranslate">UIViewController</code> subclass. <code class="notranslate">FlutterViewController</code> takes no arguments to replicate that pattern. To receive data back, I would set a <code class="notranslate">delegate</code> on the <code class="notranslate">UIViewController</code> subclass. The <code class="notranslate">delegate</code> 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 <code class="notranslate">delegate</code> method. The <code class="notranslate">delegate</code> would then be responsible for dismissing the screen.</p>
<p dir="auto">From what I've found online, the only way to pass data between Flutter and a native codebase is by <a href="https://flutter.io/docs/development/platform-integration/platform-channels" rel="nofollow">writing custom platform-specific code</a>. 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?</p>
<p dir="auto">[This is very similar to http://github.com/<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="307365660" data-permission-text="Title is private" data-url="https://github.com/flutter/flutter/issues/15798" data-hovercard-type="issue" data-hovercard-url="/flutter/flutter/issues/15798/hovercard" href="https://github.com/flutter/flutter/issues/15798">/issues/15798</a>]</p>
<p dir="auto">I wanted to open a new issue for this because the issue above is quite generic. Our clients have been complaining that ability to only send strings down is too limiting from API point of view. They would love to have initialRoute (or some similar mechanism) to support protocol buffers.</p>