8000 App goes black when there is a system dialog and locking/unlocking on Android · Issue #74801 · flutter/flutter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

App goes black when there is a system dialog and locking/unlocking on Android #74801

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

Closed
ildarsharafutdinov opened this issue Jan 27, 2021 · 8 comments
Labels
c: rendering UI glitches reported at the engine/skia or impeller rendering level engine flutter/engine repository. See also e: labels. found in release: 1.22 Found to occur in 1.22 found in release: 1.26 Found to occur in 1.26 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version

Comments

@ildarsharafutdinov
Copy link
ildarsharafutdinov commented Jan 27, 2021

Steps to Reproduce

  1. run share plugin example https://github.com/flutter/plugins/tree/share-v0.6.5+4/packages/share/example
  2. input text and tap share button
  3. block and unblock phone screen

Expected results:

Share dialog with the app view in background.

Actual results:

Share dialog with the black background instead of my app.

The same is true for any system dialog that appears above flutter activity.

E.g. the issue can be reproduced with the same example app by tapping "+ Add Image" and blocking/unblocking screen.

The same report #58002 was closed awhile ago. Screenshot is available at #58002 (comment)

@TahaTesser
Copy link
Member
TahaTesser commented Jan 27, 2021

Hi @ildarsharafutdinov
Thanks for filing the issue, I can reproduce the issue, on the emulator goes black, but on a physical Realme 6 Android 10, the screen flashes and goes white for a second then back to normal,

Based on the closed issue, it looks like a general Android issue in Flutter, not dependent on the Share plugin

code sample
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:share/share.dart';

import 'image_previews.dart';

void main() {
  runApp(DemoApp());
}

class DemoApp extends StatefulWidget {
  @override
  DemoAppState createState() => DemoAppState();
}

class DemoAppState extends State<DemoApp> {
  String text = '';
  String subject = '';
  List<String> imagePaths = [];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Share Plugin Demo',
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Share Plugin Demo'),
          ),
          body: SingleChildScrollView(
            child: Padding(
              padding: const EdgeInsets.all(24.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  TextField(
                    decoration: const InputDecoration(
                      labelText: 'Share text:',
                      hintText: 'Enter some text and/or link to share',
                    ),
                    maxLines: 2,
                    onChanged: (String value) => setState(() {
                      text = value;
                    }),
                  ),
                  TextField(
                    decoration: const InputDecoration(
                      labelText: 'Share subject:',
                      hintText: 'Enter subject to share (optional)',
                    ),
                    maxLines: 2,
                    onChanged: (String value) => setState(() {
                      subject = value;
                    }),
                  ),
                  const Padding(padding: EdgeInsets.only(top: 12.0)),
                  ImagePreviews(imagePaths, onDelete: _onDeleteImage),
                  ListTile(
                    leading: Icon(Icons.add),
                    title: Text("Add image"),
                    onTap: () async {
                      final imagePicker = ImagePicker();
                      final pickedFile = await imagePicker.getImage(
                        source: ImageSource.gallery,
                      );
                      if (pickedFile != null) {
                        setState(() {
                          imagePaths.add(pickedFile.path);
                        });
                      }
                    },
                  ),
                  const Padding(padding: EdgeInsets.only(top: 12.0)),
                  Builder(
                    builder: (BuildContext context) {
                      return RaisedButton(
                        child: const Text('Share'),
                        onPressed: text.isEmpty && imagePaths.isEmpty
                            ? null
                            : () => _onShare(context),
                      );
                    },
                  ),
                  const Padding(padding: EdgeInsets.only(top: 12.0)),
                  Builder(
                    builder: (BuildContext context) {
                      return RaisedButton(
                        child: const Text('Share With Empty Origin'),
                        onPressed: () => _onShareWithEmptyOrigin(context),
                      );
                    },
                  ),
                ],
              ),
            ),
          )),
    );
  }

  _onDeleteImage(int position) {
    setState(() {
      imagePaths.removeAt(position);
    });
  }

  _onShare(BuildContext context) async {
    // A builder is used to retrieve the context immediately
    // surrounding the RaisedButton.
    //
    // The context's `findRenderObject` returns the first
    // RenderObject in its descendent tree when it's not
    // a RenderObjectWidget. The RaisedButton's RenderObject
    // has its position and size after it's built.
    final RenderBox box = context.findRenderObject();

    if (imagePaths.isNotEmpty) {
      await Share.shareFiles(imagePaths,
          text: text,
          subject: subject,
          sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
    } else {
      await Share.share(text,
          subject: subject,
          sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
    }
  }

  _onShareWithEmptyOrigin(BuildContext context) async {
    await Share.share("text");
  }
}
flutter doctor -v
[✓] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.19042.746], locale en-US)
    • Flutter version 1.22.6 at C:\Users\Taha\Code\flutter_stable
    • Framework revision 9b2d32b605 (5 days ago), 2021-01-22 14:36:39 -0800
    • Engine revision 2f0af37152
    • Dart version 2.10.5


[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Taha\Code\SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[!] Android Studio (version 4.1.0)
    • Android Studio at C:\Users\Taha\Code\android-studio
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[✓] VS Code (version 1.52.1)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.18.1

[✓] Connected device (2 available)
    • RMX2001 (mobile)                   • EUYTFEUSQSRGDA6D • android-arm64 • Android 10 (API 29)
    • Android SDK built for x86 (mobile) • emulator-5554    • android-x86   • Android 10 (API 29) (emulator)

! Doctor found issues in 1 category.
[✓] Flutter (Channel master, 1.26.0-13.0.pre.194, on Microsoft Windows [Version 10.0.19042.746], locale en-US)
    • Flutter version 1.26.0-13.0.pre.194 at C:\Users\Taha\Code\flutter_master
    • Framework revision 71aec53acb (10 hours ago), 2021-01-26 21:53:04 -0800
    • Engine revision b11bef83a5
    • Dart version 2.12.0 (build 2.12.0-263.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Taha\Code\SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.3)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.8.30804.86
    • Windows 10 SDK version 10.0.18362.0

[✓] Android Studio (version 4.1.0)
    • Android Studio at C:\Users\Taha\Code\android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[✓] VS Code (version 1.52.1)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.18.1

[✓] Connected device (5 available)
    • RMX2001 (mobile)                   • EUYTFEUSQSRGDA6D • android-arm64  • Android 10 (API 29)
    • Android SDK built for x86 (mobile) • emulator-5554    • android-x86    • Android 10 (API 29) (emulator)
    • Windows (desktop)                  • windows          • windows-x64    • Microsoft Windows [Version 10.0.19042.746]
    • Chrome (web)                       • chrome           • web-javascript • Google Chrome 87.0.4280.141
    • Edge (web)                         • edge             • web-javascript • Microsoft Edge 88.0.705.50

• No issues found!

Could be related to #45086

Thank you

@TahaTesser TahaTesser changed the title Black background with official share plugin on android App goes black when there is a system dialog and locking/unlocking on Android Jan 27, 2021
@TahaTesser TahaTesser added engine flutter/engine repository. See also e: labels. found in release: 1.22 Found to occur in 1.22 found in release: 1.26 Found to occur in 1.26 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-android Android applications specifically c: rendering UI glitches reported at the engine/skia or impeller rendering level labels Jan 27, 2021
@ildarsharafutdinov
Copy link
Author

@TahaTesser ,

What do you mean by "a general Android issue in Fluter"?

Apparently black background is not ok. If that's a "general flutter issue", it's still the flutter issue, that needs to be fixed. Doesn't it?

@chinmaygarde
Copy link
Member

cc @xster Could this be the application lifecycle code incorrectly detecting that the application is in the background and pausing the animator?

@LuodiJackShen
Copy link

This is not a flutter bug, there are two ways to solve this problem.
1、 Override the method getBackgroundMode in FlutterActivity:

public class MyFlutterActivity extends FlutterActivity {
  ....
    @NonNull
    protected FlutterActivityLaunchConfigs.BackgroundMode getBackgroundMode() {
        return FlutterActivityLaunchConfigs.BackgroundMode.transparent;
    }
   ....
}

2、Add extra to the Intent

     Intent intent = new Intent(this, FlutterActivity.class);
     intent.putExtra("background_mode","transparent");
     startActivity(intent);

@jeff-odopass
Copy link

This is not a flutter bug, there are two ways to solve this problem.
1、 Override the method getBackgroundMode in FlutterActivity:

public class MyFlutterActivity extends FlutterActivity {
  ....
    @NonNull
    protected FlutterActivityLaunchConfigs.BackgroundMode getBackgroundMode() {
        return FlutterActivityLaunchConfigs.BackgroundMode.transparent;
    }
   ....
}

2、Add extra to the Intent

     Intent intent = new Intent(this, FlutterActivity.class);
     intent.putExtra("background_mode","transparent");
     startActivity(intent);

It's brilliantly working, thanks!

@Tumist76
Copy link
Tumist76 commented Feb 17, 2022

When using transparent, the problem with Flutter >=2.5 arises. The framework is suggesting to remove

    <meta-data
      android:name="io.flutter.embedding.android.SplashScreenDrawable"
      android:resource="@drawable/launch_background"
      />

from AndroidManifest.xml with

A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.

If backgroundMode is set to transparent, splash screen breaks and shows black screen while loading.

@huycozy
Copy link
Member
huycozy commented Mar 30, 2023

This issue seems to have been fixed on the latest stable channel as I cannot reproduce it there with share_plus: ^6.3.1. See the demo below.

Demo (Samsung Galaxy Tab A7 Lite, Android 8000 13 OneUI 5.0, SM-T225)
XRecorder_30032023_184656.mp4
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.7.8, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
    • Flutter version 3.7.8 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 90c64ed42b (34 hours ago), 2023-03-21 11:27:08 -0500
    • Engine revision 9aa7816315
    • Dart version 2.19.5
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 32.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.76.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (3 available)
    • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
    • macOS (desktop)  • macos            • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
    • Chrome (web)     • chrome           • web-javascript • Google Chrome 111.0.5563.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
[!] Flutter (Channel master, 3.9.0-18.0.pre.51, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
    • Flutter version 3.9.0-18.0.pre.51 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 659ba386f6 (3 hours ago), 2023-03-28 19:13:50 -0500
    • Engine revision 78f9c68971
    • Dart version 3.0.0 (build 3.0.0-376.0.dev)
    • DevTools version 2.22.2
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 32.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.76.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (3 available)
    • iPhone 8 Plus (mobile) • A6BF67EF-D048-430D-A097-324F146781DA • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-0 (simulator)
    • macOS (desktop)        • macos                                • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 111.0.5563.110

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

I'll be closing this issue since it has already been fixed on the latest stable channel. If you still experience this issue, kindly leave a comment below and I will reopen this. Thank you!

@huycozy huycozy closed this as completed Mar 30, 2023
@huycozy huycozy added the r: fixed Issue is closed as already fixed in a newer version label Mar 30, 2023
@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 Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: rendering UI glitches reported at the engine/skia or impeller rendering level engine flutter/engine repository. See also e: labels. found in release: 1.22 Found to occur in 1.22 found in release: 1.26 Found to occur in 1.26 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

No branches or pull requests

7 participants
0