Young
Young

Reputation: 1091

How to have widgets outside the app using flutter and kotlin?

I need a way to make a button or a container that can still be visible even when I close the app like so: https://i.sstatic.net/GTpOim.jpg. But this is just simply impossible in flutter. So what I've been doing is making a platform channel on my app and trying to make the container and button with native components. But I've been using kotlin and do not know much about this programming language. Is there a way for my code to be able to make such widgets?(I would thank you so much if you could edit my full code.)

Full Code:

Flutter:

class FloatingContainer extends StatelessWidget {

  static const platform = const MethodChannel('flutter.App.com.channel');

  @override
  Widget build(BuildContext context) {
    return Container ();
  }
  Future<Null> _showNativeView() async {}

}

Kotlin:

package com.example.swipe

import android.os.Bundle

import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugin.common.MethodChannel

class MainActivity() : FlutterActivity() {
    private val CHANNEL = "flutter.App.com.channel"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        GeneratedPluginRegistrant.registerWith(this)

        MethodChannel(flutterView, CHANNEL).setMethodCallHandler { call, result ->

        }
    }
}

Upvotes: 19

Views: 4469

Answers (3)

Vamsi
Vamsi

Reputation: 684

Apart from restriction that it won't work on IOS, there is a plugin in flutter called System Alert Window, which does the same

It shows Truecaller like overlay window, over all other apps along with callback events

Upvotes: 1

ibhavikmakwana
ibhavikmakwana

Reputation: 10121

This is known as a Draw Over Other apps.

This feature is not available in the iOS probably that's the reason flutter doesn't has this feature or official package for it.

But to achieve this feature in your application you can write up some PlatformChannels.

This permission allow you to draw on top of everything.

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications. Very few applications should use this permission; these windows are intended for system-level interaction with the user.

Constant Value: "android.permission.SYSTEM_ALERT_WINDOW"

This code can also help you out to achieve this.

You can also check out springy-heads library by Flipkart-Incubator too.

Upvotes: 5

FJBatresV
FJBatresV

Reputation: 221

Hello in this case you are searching for PlatformChannels You can review the documentation here: https://flutter.dev/docs/development/platform-integration/platform-channels or if you want i have a little post about this on my website: http://fjbatresv.com/flutter-tambien-habla-nativo/ (Select your language on the top of the post.)

Upvotes: 1

Related Questions