패키지, 저장소 및 앱 카테고리 검색

패키지 상세v3.1.0+1

focus_detector_v2

위젯이 화면에 나타나거나 화면에서 사라질 때를 감지합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
19
좋아요
51
Pub 점수
160

패키지 설치

flutter pub add focus_detector_v2

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

FocusDetectorV2는 위젯이 포커스를 얻거나 잃었을 때 이를 감지하여 화면에 나타나거나 사라졌는지를 나타내는 Flutter 패키지입니다. 실시간으로 가시성과 포커스 상태에 대한 피드백을 제공하여 사용자 상호작용이나 화면 내 존재 여부에 따라 UI 동작을 관리하는 데 이상적입니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux 등 여러 플랫폼을 지원하며 크로스플랫폼 일관성을 보장합니다. 가볍고 기존의 Flutter 프로젝트에 원활하게 통합됩니다.

사용 사례

  • 실시간으로 위젯 가시성 추적
  • 포커스 상태에 따라 애니메이션 관리하기
  • 비활성 위젯 일시 정지로 성능 최적화
  • 포커스 인식 UI 컴포넌트 구현
  • 다중 화면 앱에서 화면 전환 처리

주요 기능

  • 실시간 초점 감지
  • 크로스 플랫폼 호환성
  • 기존 위젯과의 간단한 통합
  • 포커스 획득 및 상실 이벤트를 모두 지원합니다
  • 가볍고 효율적

적합한 대상

  • 반응형 UI를 구축하는 개발자
  • 포커스 기반 논리를 필요로 하는 앱
  • 인터랙티브 폼 및 입력 필드
  • 포커스 인식이 필요한 게임 또는 미디어 플레이어
  • 접근성 중심 애플리케이션

고려 사항

  • 복잡한 위젯 트리에서 주의 깊은 조작이 필요할 수 있습니다
  • 일반적인 화면 방향 변경을 감지하는 데 적합하지 않습니다
  • 포커스 상태는 다양한 플랫폼의 동작에 따라 달라질 수 있습니다
  • 위젯 수준의 포커스에 제한되며 앱 수준의 가시성은 없음
  • 메모리 누수를 방지하기 위해 적절한 폐기 처리를 보장하세요

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Focus Detector Logo

Pub.dev Badge GitHub Build Badge Gitter Badge Effective Dart Badge MIT License Badge Flutter Platform Badge

Focus Detector

Get notified every time your widget appears or disappears from the screen.

Similar to onResume()/onPause() on Android and viewDidAppear()/viewDidDisappear() on iOS.

Focus Detector fires callbacks for you whenever something happens to take or give your widget focus. Such an event might be, for instance, the user:

  • Navigating to/from another screen;
  • Turning the device’s screen on/off while your widget is visible;
  • Switching to/from another app while your widget is visible;
  • Scrolling your widget in/out the screen;

Usage

@override
Widget build(BuildContext context) =>
    FocusDetector(
      onFocusLost: () {
        logger.i(
          'Focus Lost.'
          '\nTriggered when either [onVisibilityLost] or [onForegroundLost] '
          'is called.'
          '\nEquivalent to onPause() on Android or viewDidDisappear() on iOS.',
        );
      },
      onFocusGained: () {
        logger.i(
          'Focus Gained.'
          '\nTriggered when either [onVisibilityGained] or [onForegroundGained] '
          'is called.'
          '\nEquivalent to onResume() on Android or viewDidAppear() on iOS.',
        );
      },
      onVisibilityLost: () {
        logger.i(
          'Visibility Lost.'
          '\nIt means the widget is no longer visible within your app.',
        );
      },
      onVisibilityGained: () {
        logger.i(
          'Visibility Gained.'
          '\nIt means the widget is now visible within your app.',
        );
      },
      onForegroundLost: () {
        logger.i(
          'Foreground Lost.'
          '\nIt means, for example, that the user sent your app to the background by opening '
          'another app or turned off the device\'s screen while your '
          'widget was visible.',
        );
      },
      onForegroundGained: () {
        logger.i(
          'Foreground Gained.'
          '\nIt means, for example, that the user switched back to your app or turned the '
          'device\'s screen back on while your widget was visible.',
        );
      },
      isWidgetTest: false,
      child: Container(),
    );

Usage Scenarios

  • Turn on and off resource-consuming features, such as camera, location or bluetooth;
  • Sync your data with a remote API or local database;
  • Pause and resume video/audio playback or streaming;

Migrating from 'focus_detector'

This is a forked version of Focus Detector. It was not updated for more than a year, so I made the V2 for my personal projects. To migrate from the V1, update the pubspec.yml dependency from focus_detector: ^2.0.1 to focus_detector_v2: ^3.1.0 and adjust your import inside dart files.

Contribution

Contributions of any kind are welcome. Feel free to improve the library by creating a pull request or opening an issue.

카테고리

의존성

의존성 목록 1 개

소스 저장소

이 패키지를 사용하는 프로젝트