Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.stack.imgur.com/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 ->

        }
    }
}
like image 926
Young Avatar asked Jan 13 '19 09:01

Young


People also ask

How do I override widgets in Flutter?

You can actually achieve it by extending RaisedButton class and overriding the default properties that you need. Use MyButton where ever you wanted RaisedButton with your style. Hope this helps!

Is Flutter built entirely on widget?

Does Flutter use my operating system's built-in platform widgets? No. Instead, Flutter provides a set of widgets (including Material Design and Cupertino (iOS-styled) widgets), managed and rendered by Flutter's framework and engine. You can browse a catalog of Flutter's widgets.

Does Flutter use native widgets?

Flutter doesn't use native system components. Instead, it offers a set of its own custom widget catalog, rendered and managed by the framework's graphics engine.

How do you get widgets on Flutter?

Start a new Flutter project in Android Studio and choose Flutter Package for the project type. Put your custom widget in the lib folder. Add a folder named example to the project root. In there, add a Flutter app that demonstrates how to use your widget.


1 Answers

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.

like image 158
ibhavikmakwana Avatar answered Sep 22 '22 12:09

ibhavikmakwana