Flutter in Android
28th Dec 2023
Add-to-app
It’s sometimes not practical to rewrite your entire application in Flutter all at once. For those situations, Flutter can be integrated into your existing application piecemeal, as a library or module. That module can then be imported into your Android or iOS (currently supported platforms) app to render a part of your app’s UI in Flutter. Or, just to run shared Dart logic
visit : https://luxmi1799.github.io/
Step to Step
Open Existing
Android
Project
Android API’s
Module wizard
Run
New Flutter
Build &
Use Flutter
Step 1
Step 2
Step 3
Step 4
Integration ?
Flutter can be embedded into your existing Android application piecemeal, as a source code Gradle subproject or as AARs( Android archive).
Integrate with Android Studio
New Flutter Project with Project Type as Module
Add the Flutter module as a dependency
Android archive
Module source code
Create Android Archive (AAR)
Use command : flutter build aar
Add these dependency in setting.gradle file of host application
Next
Add a Flutter screen to an Android app
Step 1: Add FlutterActivity to AndroidManifest.xml
FlutterActivity is the simplest and most direct way to integrate Flutter within an Android app.
Step 2: Launch FlutterActivity
Import FlutterActivity in Host application ,
add code to launch FlutterActivity from whatever point in your app that you’d like
Call Flutteractivity on button click
getApplicationContext()
The previous example assumes that your Dart entrypoint is called main(), and your initial Flutter route is ‘/’. The Dart entrypoint can’t be changed using Intent, but the initial route can be changed using Intent. The following example demonstrates how to launch a FlutterActivity that initially renders a custom route in Flutter.
Intial route another than main in Flutter
The use of the withNewEngine() factory method configures a FlutterActivity that internally create its own FlutterEngine instance.
Step 3: Use a cached FlutterEngine
Every FlutterActivity creates its own FlutterEngine by default. Each FlutterEngine has a non-trivial warm-up time. This means that launching a standard FlutterActivity comes with a brief delay before your Flutter experience becomes visible. To minimize this delay, you can warm up a FlutterEngine before arriving at your FlutterActivity, and then you can use your pre-warmed FlutterEngine instead.
Description
Fimally call this FlutterActivity in Android
With a pre-warmed, cached FlutterEngine, you now need to instruct your FlutterActivity to use the cached FlutterEngine instead of creating a new one. To accomplish this, use FlutterActivity’s withCachedEngine()
Finally We have Done
ThankYou!
LUXMI GUPTA
Mobile developer @Nippon
visit : https://github.com/luxmi1799
https://linktr.ee/luxmigupta