Last active
December 9, 2020 21:30
-
-
Save xster/04e930aabadbd40b90dd2bcce7931ba7 to your computer and use it in GitHub Desktop.
Pulling synchronous data from Flutter on the platform vs platform cache for Dart feature developers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// With a platform-thread Dart isolate/cache | |
pageA.java - our feature team just owns this one file on the Java side | |
-------------------------- | |
class FeatureAFlutterActivity extends Activity implements SomeLibraryCallback { | |
// Long lived engine, owned by someone else, given to me by | |
// an injector. | |
@Inject FlutterEngine flutterEngine; | |
@Inject SomeLibraryHandle someLibraryHandle; | |
public void onCreate() { | |
someLibraryHandle.setListener(this); | |
} | |
// SomeLibraryCallback | |
public X someLibraryCallbackWantingXSynchronously() { | |
// I, the Dart dev, have to add this one line to this Java file. | |
return SynchronousPigeonApi(flutterEngine).getAnX(); | |
} | |
} | |
-------------------------- | |
// With a platform-side cache | |
pageA.java - our feature team just owns this one file on the Java side | |
-------------------------- | |
class FeatureAFlutterActivity extends Activity | |
implements SomeLibraryCallback, PigeonFeatureAHostApi { | |
// Long lived engine, owned by someone else, given to me by | |
// an injector. | |
@Inject FlutterEngine flutterEngine; | |
@Inject SomeLibraryHandle someLibraryHandle; | |
public void onCreate() { | |
someLibraryHandle.setListener(this); | |
// This doesn't exist today since there's one big setup, but we can | |
// definitely split it in the schema for handlers that don't have | |
// the same lifecycle. | |
Pigeon.setupApiForFeatureA(flutterEngine.getDartExecutor(), this); | |
} | |
// PigeonFeatureAHostApi | |
public void pigeonCallbackToCacheX(X anX) { | |
// Where do I put anX? The FlutterEngine is longer lived than me | |
// (Activity). It seems like I need to @Inject some other | |
// container that has the same lifecyle as the FlutterEngine instance | |
// I got to store it. I have to ask the infra team where is the | |
// FlutterEngine made and find a nice sibling or parent where | |
// it's semantically clean to store this X thing. Then, as a Dart | |
// dev, I have to go figure out how this whole @Inject codegen | |
// thing works and how to get gradle to build it again so this | |
// IDE I don't like to use can autocomplete again. | |
} | |
// SomeLibraryCallback | |
public X someLibraryCallbackWantingXSynchronously() { | |
// Where do I get this X instance? I can't keep it just here in the | |
// activity instance that our team owns since that value may have never | |
// changed or been given to us since our Activity was created. How do I get | |
// the previous value the engine emitted? | |
} | |
} | |
-------------------------- | |
Then rinse and repeat for objective-c, learn how GIMMify works. Learn about | |
c pre-processor macros used for dependency injection. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment