Giter VIP home page Giter VIP logo

focus_detector's People

Contributors

edsonbueno avatar kurtinge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

focus_detector's Issues

detect app in background, app closed, no internet. & custom triggers

if you double tap the home button on iphone, it minimizes current app and shows all apps tiled (app is not in foreground) but doesn't trigger a warning that the app in inactive/background.

is it possible to detect if the app is closed?

also, would be nice to add more detection triggers such as when there is no internet or if you're on cellular/wifi or even custom triggers

thanks

On initState, init _isAppInForeground

Could init _isAppInForeground on initState?

because some native dialog pop on ui faster.
then flutter ui render.

  @override
  void initState() {
    WidgetsBinding.instance.addObserver(this);
    _isAppInForeground = (WidgetsBinding.instance.lifecycleState ?? AppLifecycleState.resumed) == AppLifecycleState.resumed;
    super.initState();
  }

No Support for updateInterval

onFocusGained is fired with a short delay which is undesirable in my case causing the widget to refresh its contents about .5-1sec after the user returns to the screen.

It seems visibility_detector has implemented a default delay which can be overridden by setting the instance updateInterval. This option does not seem to be available in focus_detector.

I was able to workaround this issue by adding the visibility_detector package directly to my project (which is not ideal) and setting the updateInterval from there.

VisibilityDetectorController.instance.updateInterval = Duration.zero;

Not handling onFocusGained properly

This package treats visibility and focus as synonymous but they are not.

On android, for example...you'd have to use onWindowFocusChanged to detect whether the app has regained focus after switching back to it.

The clipboard, for example, cannot be accessed until the app is in focus and accessing the clipboard on "onFocusGained" from this package returns null because there is a brief delay between onResume and when the app actually gains focus. The code below can be used to detect focus on android:

public void onWindowFocusChanged(boolean hasFocus) {         
     super.onWindowFocusChanged(hasFocus);
     if(hasFocus) 
         Toast.makeText(context, text, duration).show();
 }

Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.

../../Software/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/focus_detector-2.0.1/lib/focus_detector.dart:54:20: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.

  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Software/FlutterSDK/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance?.addObserver(this);
    ^
    ../../Software/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/focus_detector-2.0.1/lib/focus_detector.dart:162:20: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Software/FlutterSDK/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance?.removeObserver(this);
    ^
    ../../Software/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/visibility_detector-0.2.2/lib/src/visibility_detector_layer.dart:126:28: Warning: Operand of null-aware operation '?.' has type 'RendererBinding' which excludes null.
  • 'RendererBinding' is from 'package:flutter/src/rendering/binding.dart' ('../../Software/FlutterSDK/flutter/packages/flutter/lib/src/rendering/binding.dart').
    assert(RendererBinding.instance?.renderView != null);
    ^
    ../../Software/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/visibility_detector-0.2.2/lib/src/visibility_detector_layer.dart:127:50: Warning: Operand of null-aware operation '!' has type 'RendererBinding' which excludes null.
  • 'RendererBinding' is from 'package:flutter/src/rendering/binding.dart' ('../../Software/FlutterSDK/flutter/packages/flutter/lib/src/rendering/binding.dart').
    var clipRect = Offset.zero & RendererBinding.instance!.renderView.size;
    ^
    ../../Software/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/visibility_detector-0.2.2/lib/src/visibility_detector_layer.dart:170:26: Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which excludes null.
  • 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../Software/FlutterSDK/flutter/packages/flutter/lib/src/scheduler/binding.dart').
    SchedulerBinding.instance!.addPostFrameCallback((timeStamp) {
    ^
    ../../Software/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/visibility_detector-0.2.2/lib/src/visibility_detector_layer.dart:193:22: Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which excludes null.
  • 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../Software/FlutterSDK/flutter/packages/flutter/lib/src/scheduler/binding.dart').
    SchedulerBinding.instance!

error: "name" field doesn't match expected name "focus_detector".

I checkout my project with my new MacBook Pro, chip Apple M1

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.4, on macOS 13.0.1 22A400 darwin-arm (Rosetta), locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.75.0)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

dependencies:
  focus_detector:
    git:
      url: https://github.com/ifnyas/focus_detector.git
      ref: master

And got an error after run: flutter pub get

Error on line 1, column 7: "name" field doesn't match expected name "focus_detector".

1 │ name: focus_detector_v2
│ ^^^^^^^^^^^^^^^^^

pub get failed (65; ╵)
exit code 65

Please adapt to flutter3.0

../../../Development/flutter/.pub-cache/hosted/pub.flutter-io.cn/focus_detector-2.0.1/lib/focus_detector.dart:54:20: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.

  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Development/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance?.addObserver(this);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.