Flutter Module in Android App

Jan 19 · 3 min read

Today I’m going to import a Flutter module into an existing Android app. Moreover, I’ll call native methods from that Flutter screen. Because I solved the issue which I mentioned in the last paragraph of my previous story, thanks to Muhannad Fakhouri.

I created a basic Android app and imported a Flutter module. By the FloatingActionButton, I’m starting the FlutterActivity with a route and put a parameter for the title to handle on the Dart side.

FloatingActionButton fab = findViewById(R.id.fab);

fab.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new FlutterActivity
.putExtra("title", "Title")


I located MyFlutterActivity.java on the same folder as other java classes and defined the activity in Manifest.xml.

<activity android:name=".MyFlutterActivity"

Then, I override the onCreate method of MyFlutterActivity to get the title parameter and set it to a global variable:

String title = "";

protected void onCreate(Bundle savedInstanceState) {
Bundle extras = getIntent().getExtras();
title = extras.getString("title");

And override the configureFlutterEngine to handle the method calls from the Dart side of the app.

public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {

new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL).setMethodCallHandler(((methodCall, result) -> {
if (methodCall.method.equals("getBatteryLevel")) {
} else if (methodCall.method.equals("getTitle")) {
result.success(title); // It returns "Title".
} else {

Now, I can easily call the related invokeMethod in the initState of SecondScreen.dart to get the title that passed as an argument from the native side.

void initState() {


getTitle() async {
String res = await platformMethodChannel.invokeMethod('getTitle');

setState(() {
title = res;

Voila! The parameter “Title” is on the screen.

And I can invoke the other methods like getBatteryLevel in this Flutter screen.

void _incrementCounter() async {
try {
String response =
await platformMethodChannel.invokeMethod('getBatteryLevel');

setState(() {
title = response;
} on PlatformException catch (e) {

setState(() {

The parameter has changed as demonstrated below.

You can access the GitHub repo about this story from here:

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store