You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
samples/add_to_app/multiple_flutters
Jenn Magder c6bee7aa93
Add-to-app iOS flutter_post_install post_install hook (#1079)
3 years ago
..
multiple_flutters_android Remove binaries from samples. (#1057) 3 years ago
multiple_flutters_ios Add-to-app iOS flutter_post_install post_install hook (#1079) 3 years ago
multiple_flutters_module Remove git:// url, update deps, fix `destop_photo_search` (#1052) 3 years ago
README.md Update README.md (#858) 3 years ago

README.md

multiple_flutters

This is a sample that shows how to use the Flutter Engine Groups API to embed multiple instances of Flutter into an existing Android or iOS project.

Getting Started

For iOS instructions, see: multiple_flutters_ios.

For Android instructions, see: multiple_flutters_android.

Requirements

  • Flutter -- after Flutter v2
  • Android
    • Android Studio
  • iOS
    • Xcode
    • Cocoapods

Flutter Engine Group

These examples use the Flutter Engine Group APIs on the host platform which allows engines to share memory and CPU intensive resources. This leads to easier embedding of Flutter into an existing app since multiple entrypoints can be maintained via a FlutterFragment on Android or a UIViewController on iOS. Before FlutterEngineGroup, users had to juggle the usage of a small number of engines judiciously.

More info on those API's can be found in the source code:

Important Files

iOS

Android

Data Synchronization Description

This sample code performs data synchronization to share data between the host platform and multiple instances of Flutter by combining the Observer design pattern and Flutter platform channels. Here is how it works:

  • The definitive source of truth for the data lives in the host platform data model.
  • Every host view displaying Flutter content maintains: a Flutter engine, a bidirectional platform channel, and a subscription to the host data model.
  • Flutter instances maintain a copy of the data they are interested in reading, and this data is seeded by the host when the instance is first displayed.
  • Mutations from Flutter code are sent to the host platform via the channel. The host platform performs the mutations, and then notifies all host view controllers and Flutter engines of the new value.
  • Mutations from host code happen directly on the data model who notifies host view controllers and Flutter engines of the new value.

This is just one possible way to synchronize the data between the host platform and multiple Flutter instances. A more complete implementation is proposed in the work of flutter/issues/72030.