Skip to content

A demonstration of adding Flutter Module inside a native android App.

Notifications You must be signed in to change notification settings

shakiz/flutter_add_to_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Flutter - Add Module Inside Native

Table of Contents

  1. About The Project
  2. Implementation Features
  3. Methods
  4. Basic Mechanisms
  5. Method to Choose
  6. Installation
  7. Limitations
  8. Contributing

About The Project

Incorporating a Flutter module into an existing Android native app, also known as Add-to-App implementation, offers developers the flexibility to leverage Flutter's rich UI capabilities within their Android projects. This documentation provides a step-by-step guide to various methods available for integrating a Flutter module into an Android native app. There are several popular methods that are suggested by Flutter, and amongst them some are a good fit, others might not. The key of this solution is, embedding the Flutter module to your native application in a subproject. As the cross-platform feature of Flutter, one single Flutter module can be added to both Android and iOS projects.

Implementation Features

This project includes demonstration of below mentioned technical items.

  • Debugging from native to flutter app
  • Data pass between native to flutter and flutter to native
  • Complex object passing (JSON data/object/list)
  • Specific Screen Navigation, Flow end, Flow trigger, Flow navigation.
  • Basic routing
  • Conditional flow trigger
  • Callback mechanism on different events
  • Close flutter screen and send back the data to native or have some listener to know that flutter activity shutdown

Methods

  • Option A - Depend on the Android Archive (AAR)
  • Option B - Depend on the module’s source code

Basic Mechanisms

To launch a Flutter screen from an existing iOS/Android, we need to start a FlutterEngine and a FlutterViewController/FlutterActiviy depending on the OS.

The FlutterEngine serves as a host to the Dart VM and Flutter runtime, and the FlutterViewController/FlutterActivity attaches to a FlutterEngine to pass input events into Flutter and to display frames rendered by the FlutterEngine. The FlutterEngine may have the same lifespan as your FlutterViewController/FlutterActivity or outlive our FlutterViewController/FlutterActivity.

Methods to Choose

Each of the methods provides a way to integrate the Flutter Module into native app. But choosing the right one might depend on the above mentioned points. 

For example, if we choose the Android Archive (AAR) way then we have to consider that it works with native by generating an AAR file, which leads to issues while debugging. Also there are times when we need to regenerate the AAR file after we made some changes into Flutter Module.

On the other hand, module’s source code provides a much easier way to implement and debugging is more convenient compared to AAR. Also, making changes and getting the reflection is not that much of an issue with this way.

Installation

  1. Clone the repo
    git clone https://github.com/shakiz/flutter_add_to_app
  2. Run Flutter Pub get
    flutter pub get
  3. Run
    flutter run

Limitations

  • Packing Multiple Flutter Libraries: In add-to-app setups, it's essential to understand that packing multiple Flutter libraries into an application isn't directly supported. Each Flutter module is typically integrated into a specific native app module, and there may be challenges when attempting to include multiple Flutter modules within the same native app.
  • Performance Overhead: While Flutter provides excellent performance out-of-the-box, integrating Flutter into an existing app may introduce additional performance overhead, especially if not optimised properly.
  • Testing and Debugging: Testing and debugging can be more challenging in an add-to-app setup, especially when dealing with issues that span both Flutter and native code.
  • Support for AndroidX: In add-to-app setups on Android, the Flutter module only supports AndroidX applications. AndroidX is the modern Android library suite that replaces the now-deprecated Android Support Libraries.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Releases

No releases published

Packages

No packages published