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 : AppLifecycleState not work if devices in locked screen #47868

Closed
zgramming opened this issue Dec 27, 2019 · 4 comments
Closed

Flutter : AppLifecycleState not work if devices in locked screen #47868

zgramming opened this issue Dec 27, 2019 · 4 comments
Labels
engine flutter/engine repository. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically

Comments

@zgramming
Copy link

zgramming commented Dec 27, 2019

I use AppLifeycleState to detect Behaviour my app when the user using it. For detect my app not being used, i used

  • AppLifecycleState.paused
  • AppLifecycleState.inActive
  • AppLifecycleState.detached

Because i want detect if my App not being used for 1 second, i throw user to Confirmation Fingerprint (Like Whatsapp). Everything is fine i can detect if my app not being used if user press recent app, Home button and throw user to Confirmation Fingerprint if user comeback again.

But the problem is , When devices screen in locked up then it opened again , user not throwing to Confirmation Fingerprint.

I surely can see in console my app is AppLifecycleState.paused and AppLifecycleState.inActive, but strangely if i hot reload ctrl +s in my IDE my app throwing me to Confirmation Fingerprint.

Why can be like this ?

Working 1

applifecycle1

Working 2

applifecycle2

Not Working !

applifecycle not working

Already tested too in real Device (Redmi Note 4) , and still not working.

Source Code AppLifecycleState

@override
  void didChangeAppLifecycleState(AppLifecycleState state) async {
    setState(() => _appLifecycleState = state);
    if (widget.userBox == null) {
      print('Box User Null');
      return;
    } else {
      if (widget.userModelHive.fingerPrint || widget.userModelHive.pinCode) {
        if (_appLifecycleState != AppLifecycleState.resumed) {
          //? Berarti Lifecylenya InActive , Paused , Detached , Maka Simpan Waktu Keluarnya
          final actionBox = await repository.changeDateExit(
            userModelHive: UserModelHive()
              ..id = widget.userModelHive.id
              ..giverName = widget.userModelHive.giverName
              ..pinCode = widget.userModelHive.pinCode
              ..fingerPrint = widget.userModelHive.fingerPrint
              ..darkMode = widget.userModelHive.darkMode
              ..tokenExpiry = true
              ..durationToken = widget.userModelHive.durationToken
              ..dateExit = DateTime.now()
                  .add(Duration(seconds: widget.userModelHive.durationToken)),
          );
          print(state);
          return actionBox;
        } else {
          print('Resumed Lifecycle');
        }
      }
    }
    if (mounted) {
      setState(() {});
    }
    super.didChangeAppLifecycleState(state);
  }
@janmoppel
Copy link

Hello @zgramming !

Thank you for posting an issue.
Can you please also attach the flutter doctor -v command output?

@janmoppel janmoppel added framework flutter/packages/flutter repository. See also f: labels. waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Dec 27, 2019
@zgramming
Copy link
Author

Flutter doctor -v

PS C:\Project Flutter\playstore_app\debt_diary> flutter doctor -v
[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.18362.535], locale en-US)
    • Flutter version 1.12.13+hotfix.5 at C:\flutter\flutter
    • Framework revision 27321ebbad (2 weeks ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

 
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
    • Android SDK at C:\Users\user\AppData\Local\Android\Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[√] Android Studio (version 3.5)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.41.1)
    • VS Code at C:\Users\user\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.7.1

[√] Connected device (1 available)
    • Redmi Note 4 • 1a96d23a9904 • android-arm64 • Android 7.0 (API 24)

• No issues found!
PS C:\Project Flutter\playstore_app\debt_diary> 

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 27, 2019
@goderbauer goderbauer added engine flutter/engine repository. See also e: labels. dependency: android Android team may need to help us platform-android Android applications specifically and removed dependency: android Android team may need to help us labels Jan 6, 2020
@jmagman jmagman added this to Awaiting triage in Mobile - Android engine review Feb 25, 2020
@xster xster moved this from Awaiting triage to Engineer reviewed in Mobile - Android engine review May 13, 2020
@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 18, 2020
@markusaksli-nc markusaksli-nc removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 9, 2020
@markusaksli-nc
Copy link
Member

Closing this as not reproducible on the latest master 1.23.0-8.0.pre.254.

flutter doctor -v
[✓] Flutter (Channel master, 1.23.0-8.0.pre.254, on Mac OS X 10.15.7 19H2 x86_64, locale en-GB)
    • Flutter version 1.23.0-8.0.pre.254 at /Users/markus/development/flutter_master
    • Framework revision 0d8696f655 (2 hours ago), 2020-10-09 01:12:02 -0400
    • Engine revision 349889833c
    • Dart version 2.11.0 (build 2.11.0-203.0.dev)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at /Users/markus/Library/Android/sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: /Users/markus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6821437/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.0.1, Build version 12A7300
    • CocoaPods version 1.9.3

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

[✓] Android Studio (version 4.0)
    • Android Studio at /Users/markus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6821437/Android Studio.app/Contents
    • Flutter plugin version 50.0.1
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

 
[✓] Connected device (4 available)            
    • Nevercode’s iPhone (mobile) • b668e524315069f3db3661ac11ff1f66afafebdb • ios            • iOS 13.7
    • macOS (desktop)             • macos                                    • darwin-x64     • Mac OS X 10.15.7 19H2 x86_64
    • Web Server (web)            • web-server                               • web-javascript • Flutter Tools
    • Chrome (web)                • chrome                                   • web-javascript • Google Chrome 85.0.4183.121

• No issues found!

Code sample
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  AppLifecycleState previous;
  Color color = Colors.red;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Sample',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Sample'),
        ),
        body: Center(
          child: GestureDetector(
              onTap: () => setState(() => color = Colors.white),
              child: Container(
                color: color,
              )),
        ),
      ),
    );
  }


  @override
  void initState() {
    WidgetsBinding.instance.addObserver(this);
    super.initState();
  }


  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    print(state);
    if ((previous == AppLifecycleState.paused ||
            previous == AppLifecycleState.inactive ||
            previous == AppLifecycleState.detached) &&
        state == AppLifecycleState.resumed) setState(() => color = Colors.red);
    previous = state;
  }
}

@zgramming If you are still experiencing this on the latest stable or any other channel, please provide a minimal complete reproducible code sample and your flutter doctor -v, and I'll reopen.

@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 Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
engine flutter/engine repository. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically
Projects
Mobile - Android engine review
  
Engineer reviewed
Development

No branches or pull requests

5 participants