flutter / website

Flutter documentation web site
https://docs.flutter.dev
Other
2.8k stars 3.21k forks source link

Document best practice for developing add-to-app module integrated and standalone #7774

Open xster opened 4 years ago

xster commented 4 years ago

@blasten called this out last year. This was also extensively worked on by our China customers https://www.infoq.cn/article/iYGyKQowuiUN_Gi2hHDo.

For lightweight "detached" development, it makes sense for Flutter module developers to be able to bootstrap their module and launch/test their module both in a standalone fashion and also in normal 'production' mode integrated into their bigger host app.

Document the best practices for this approach.

Relates to https://github.com/flutter/flutter/issues/32989 and http://flutter.dev/go/everything-builds-from-a-module as well.

I'm of the opinion that the standalone run shell should be another (albeit simpler) add-to-app host app that wraps the same Flutter module and that supplies it with upstream dependencies, data etc.

sfshaza2 commented 4 years ago

Is this feature available, @xster? In other words, is this only a documentation issue for flutter.dev?

xster commented 4 years ago

SEO: wrapper, bootstrap, loader, preview, data

xster commented 4 years ago

This is still generally the current thinking:

  1. In the most lightweight case, where the Flutter module doesn't need any bootstrap data, just flutter run in the module directory. This runs the module in a very basic ephemeral wrapper project.
  2. In a middle case where some platform-side setup is needed but where you also don't want to build and launch your full/heavy host app to test your Flutter module, create your own parallel wrapper platform app (don't modify the .ios/.android apps) to bootstrap and inject data into your Flutter module for test.
  3. For a full integration test, run the Flutter module inside your normal platform host app.
jmagman commented 1 year ago

@atsansone why wouldn't this issue live in the website repo? https://docs.flutter.dev/development/add-to-app

jmagman commented 1 year ago

Sorry, I misread this, I thought it was transferred from website to flutter, not the other way. Carry on. 🙂

miquelbeltran commented 1 year ago

Hi all, to me, it looks like that https://docs.flutter.dev/add-to-app and the samples in https://github.com/flutter/samples/tree/main/add_to_app contain examples of this usecase.

You can use the Entry point annotation as explained here: https://docs.flutter.dev/add-to-app/ios/add-flutter-screen#dart-entrypoint to have a different entry point for your Flutter module when you run the module embedded intro a native app, while still running the default main() method as entry point when running it standalone.

Another alternative is running the module with a different route from the native app than when running standalone. You would use setInitialRoute from the native app as described here: https://docs.flutter.dev/add-to-app/android/add-flutter-screen#initial-route-with-a-cached-engine for example /mini, while for example the default route when standalone would be /.

Do you think this would be enough? Or a more specific explanation is still missing?