1 of 20

Flutter in Android

28th Dec 2023

2 of 20

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/

3 of 20

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

4 of 20

Integration ?

Flutter can be embedded into your existing Android application piecemeal, as a source code Gradle subproject or as AARs( Android archive).

5 of 20

Integrate with Android Studio

    • Create new Flutter Project

6 of 20

New Flutter Project with Project Type as Module

7 of 20

Add the Flutter module as a dependency

Android archive

Module source code

8 of 20

Create Android Archive (AAR)

Use command : flutter build aar

Add these dependency in setting.gradle file of host application

9 of 20

10 of 20

Next

11 of 20

Add a Flutter screen to an Android app

12 of 20

Step 1: Add FlutterActivity to AndroidManifest.xml

FlutterActivity is the simplest and most direct way to integrate Flutter within an Android app.

13 of 20

Step 2: Launch FlutterActivity

Import FlutterActivity in Host application ,

add code to launch FlutterActivity from whatever point in your app that you’d like

14 of 20

Call Flutteractivity on button click

getApplicationContext()

15 of 20

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.

16 of 20

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

17 of 20

Fimally call this FlutterActivity in Android

18 of 20

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()

19 of 20

Finally We have Done

20 of 20

ThankYou!

LUXMI GUPTA

Mobile developer @Nippon

visit : https://github.com/luxmi1799

https://linktr.ee/luxmigupta