Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter PlatformView on Android 6.0 the default background is black #26505

Closed
coltorchen opened this issue Jan 14, 2019 · 11 comments
Closed

Flutter PlatformView on Android 6.0 the default background is black #26505

coltorchen opened this issue Jan 14, 2019 · 11 comments
Labels
a: platform-views Embedding Android/iOS views in Flutter apps e: device-specific Only manifests on certain devices e: OS-version specific Affects only some versions of the relevant operating system engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-android Android applications specifically

Comments

@coltorchen
Copy link

coltorchen commented Jan 14, 2019

i try to use PlatformView to expose a native Android ListView as a Flutter Widget.
when i run example on Android 7.0+,ListView background looks good.
(Mobile device: Redmi Note 4X - MIUI 9.6 - Android 7.0)
image

but when i run example on Android 6.0, ListView background is black, maybe the background color's alpha is 0 ?
(Mobile device: Redmi Note 4 - MIUI 10 - Android 6.0 )
image

#######################################################################
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):

[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14 18A391, locale
    zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] Android Studio (version 3.2)
[✓] Connected device (1 available)
@zoechi zoechi added e: device-specific Only manifests on certain devices platform-android Android applications specifically a: platform-views Embedding Android/iOS views in Flutter apps labels Jan 14, 2019
@zoechi zoechi added this to the Goals milestone Jan 14, 2019
@zoechi
Copy link
Contributor

zoechi commented Jan 14, 2019

To investigate we would need a minimal runnable reproduction
as a single file so that we can just copy your code into lib/main.dart of a new project and run to reproduce or in this case perhaps a project published to GitHub.

@zoechi zoechi added the engine flutter/engine repository. See also e: labels. label Jan 14, 2019
@figo-fe
Copy link

figo-fe commented Mar 13, 2019

I have the same problem. @zoechi @linuxomk
flutter code:

class Demo extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Container(
      child: AndroidView(
        viewType: 'nativeViewDemo'
      ),
    );
  }
}

Android code:

public class DemoView {
    public static void registerWith(Registrar registrar) {
        registrar.platformViewRegistry().registerViewFactory("nativeViewDemo", new NativeViewFactory(registrar.messenger()));
    }
}

public class NativeViewFactory extends PlatformViewFactory {
    private final BinaryMessenger messenger;

    public NativeViewFactory(BinaryMessenger messenger) {
        super(StandardMessageCodec.INSTANCE);
        this.messenger = messenger;
    }

    @Override
    public PlatformView create(Context context, int id, Object args) {
        return new NativeView(context, messenger, id);
    }
}

class NativeView implements PlatformView {
    @Override
    public View getView() {
        return new FrameLayout();
    }
}

Flutter Doctor

[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.3 18D109, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
        brew update
        brew install --HEAD usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
[✓] Android Studio (version 3.3)
[✓] VS Code (version 1.32.1)
[✓] Connected device (1 available)

The background is darkGray in Android 6.0, but white above 6.0.
The code may not run directly, but it can show what I mean.

@lzdon
Copy link

lzdon commented Mar 16, 2019

same issue. i used AndroidView to show barrage, its background is white and video below is invisiable

@lzdon
Copy link

lzdon commented Mar 18, 2019

i solve this temporarily by using reflection .

    override fun getView(): View {
        makeWindowTransparent()
        return mDanmakuView
    }

    private fun makeWindowTransparent() {
        mDanmakuView.post {
            try {
                var parent = mDanmakuView.parent ?: return@post
                while (parent?.parent != null) {
                    parent = parent.parent
                }
                val decorView = parent.javaClass.getDeclaredMethod("getView").invoke(parent)
                val windowField = decorView.javaClass.getDeclaredField("mWindow")
                windowField.isAccessible = true
                val window = windowField.get(decorView) as Window
                windowField.isAccessible = false
                window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
                log(window.toString())
            } catch (e: Exception) {
                Log.d("LiveDanmakuView", "makeWindowTransparent failed: $e")
            }
        }
    }

@HustLion
Copy link

The method @lzdon provided works, but for dynamic content like lottie animation, the animation will fails to clear its frames, resulting in all frames painted one over another. Is there any way to get PlatformView provide a transparent background by default?

@PenF00k
Copy link

PenF00k commented Jun 29, 2019

I'm trying to use flutter_lottie plugin and it gives me gray background color on android. Could someone please provide a workaround for this?

@quanNullable
Copy link

Since i can't use flutter_lottie,it gives me white background color on android,I have to replac all lottie animation with videos,Could someone please help me?

@jmagman jmagman added this to Awaiting triage in iOS Platform - platform view review Feb 25, 2020
@jmagman jmagman removed this from Awaiting triage in iOS Platform - platform view review Feb 25, 2020
@TahaTesser TahaTesser added the e: OS-version specific Affects only some versions of the relevant operating system label Mar 12, 2020
@kf6gpe kf6gpe added the P2 Important issues not at the top of the work list label May 29, 2020
@Hixie Hixie removed this from the None. milestone Aug 17, 2020
@darshankawar
Copy link
Member

@coltorchen since I don't have the specific device with 6.0 OS to verify this, but can you confirm if this is still a valid issue using latest Flutter version ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 2, 2020
@pedromassangocode
Copy link

Without additional information, we are unfortunately not sure how to resolve this issue.
We are therefore reluctantly going to close this bug for now.
Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away!
Thanks for your contribution.

Could everyone who still has this problem please file a new issue with the exact description of what happens, logs, and the output of flutter doctor -v.
All system setups can be slightly different, so it's always better to open new issues and reference related issues.

Mobile - Android platform view review automation moved this from Awaiting triage to Engineer reviewed Dec 23, 2020
@pedromassangocode pedromassangocode removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 23, 2020
@bashcious
Copy link

Hi am currently facing this same issue, I want to show a widget from native and make the Android view background transparent, i tried on mobile device and it works fine, but when run on android tv marshmallow 6.0 API level 23, the background is always black. I am using flutter 1.22.6 and i also tried the method provided by @lzdon; it throws an exception failed: java.lang.NoSuchFieldException: No field mWindow in class Lcom/android/internal/policy/PhoneWindow$DecorView; (declaration of 'com.android.internal.policy.PhoneWindow$DecorView' appears in /system/framework/framework.jar:classes2.dex)

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: platform-views Embedding Android/iOS views in Flutter apps e: device-specific Only manifests on certain devices e: OS-version specific Affects only some versions of the relevant operating system engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-android Android applications specifically
Projects
Development

No branches or pull requests