Blog

Mobile development: Dismissing the Flutter module in Android apps

Wondering how to quickly dismiss the Flutter module in you Android mobile app? This short tutorial is for you!

In my previous post, I was showing you how to dismiss FlutterViewController in iOS apps.

This time, I’d like to focus on the Android side of things. So let’s check, how to dismiss the Flutter module (added as AAR) from an Android app.

It is way easier than in Xcode, to be honest.

Flutter as an Android package module

Flutter can be used not only as a standalone app but also as a framework - injected portion of code that works on two main mobile platforms (Android, iOS).

In iOS, you can build a CocoaPods module or an iOS framework. On Android, you create an AAR module that can be simply imported inside an app written in Kotlin or Java.

How to close Flutter from an Android app

In iOS apps, we needed to call the MethodChannel functionality to close the Flutter module.

With Android, the whole process is much easier. We just need to call FlutterEngine - exactly as shown by Google in its tutorial. Of course, if you want to monitor this functionality, you can always use MethodChannel.

In Flutter, it is done with a method called inside the dismissed function.

Something like this:

await channel.invokeMethod('dismissView');

In Android, you do it like this:

channel.setMethodCallHandler { call, result ->
    if (call.method.equals("dismissView")) {
        println("Flutter View  has been dismissed");
    }
}

However, the core of closing the Flutter module is a method called inside Flutter:

SystemNavigator.pop();

This will immediately close the Flutter app (in this case, the module used inside an Android app).

If you use the `MethodChannel, you can get back information on the action that has just been performed (e.g. whether a function is working).

Worth knowing - this function doesn’t work with iOS. In that case, you should close FlutterViewController from the native app.

That’s all for now, folks.

Looking for mobile development experts? Drop us a line.

Check our latest product - it's based on our experience of managing over 50-people strong company. The tool we're missing as a small company and not an enterprise.

humadroid.io is an employee and performance management software. It's an unique tool allowing everyone to be in the loop - by having up to date info about co-workers, time-off, benefits, assets, helping with one-on-ones, being a go-to place for company-wide announcements.

Check out humadroid.io
Top

Contact us

* Required fields

The controller of your personal data provided via this contact form is Prograils sp. z o.o., with a registered seat at Sczanieckiej 9A/10, 60-215 Poznań. Your personal data will be processed in order to respond to your inquiries and for our marketing purposes (e.g. when you ask us for our post-development, maintenance or ad hoc engagements for your app). You have the rights to: access your personal data, rectify or erase your personal data, restrict the processing of your personal data, data portability and to object to the processing of your personal data. Learn more.

Notice

We do not track you online. We use only session cookies and anonymous identifiers for the purposes specified in the cookie policy. No third-party trackers.

I understand
Elo Mordo!Elo Mordo!