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

패키지 상세v1.0.5

visibility_aware_state

가시성을 인지하는 StatefulWidgets를 위한 상태입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.1천
좋아요
34
Pub 점수
150

패키지 설치

flutter pub add visibility_aware_state

패키지 개요

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

위젯의 가시성에 따라 상태를 관리하기 위해 StatefulWidget을 확장하는 플러터 패키지입니다. 위젯이 뷰포트 내에서 보이거나 숨겨질 때 자동으로 감지하여 효율적인 리소스 관리와 최적화된 성능을 가능하게 합니다. 애니메이션, 비디오 재생 또는 사용자가 위젯을 볼 수 있을 때만 실행되어야 하는 데이터 가져오기 등에 적합합니다. 기존의 StatefulWidgets에 큰 코드 변경 없이 원활하게 통합됩니다.

사용 사례

  • 가시성에 따라 애니메이션 최적화
  • 비디오 또는 오디오 재생 관리
  • 지연로딩 콘텐츠
  • 화면 외 위젯의 CPU 사용량 줄이기
  • 스크롤 기반 트리거 처리

주요 기능

  • 자동 가시성 감지
  • 최소한의 보일러플레이트
  • 기존 StatefulWidgets와 호환됩니다
  • 모든 주요 플랫폼을 지원합니다
  • 효율적인 자원 관리

적합한 대상

  • 앱 성능 최적화하는 개발자
  • 스크롤 가능한 목록 또는 캐러셀이 있는 앱
  • 미디어 집약형 애플리케이션
  • 지연 로딩이 필요한 앱

고려 사항

  • 복잡한 중첩 레이아웃에서는 예상대로 작동하지 않을 수 있습니다
  • 사용자 정의 렌더링 개체에서 신중한 처리가 필요합니다
  • 뷰포트 내에서만 보이도록 제한됨
  • 비 UI 상태 추적에 적합하지 않음
  • 정확한 위젯 트리 구조에 의존함

원본 README

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

visibility_aware_state

A state for StatefulWidgets that is aware of its visibility.

That can be useful for screen view tracking or e.g. if your app shows files it can be used to automatically refresh the files when the app is reopened again.

In Android, Activity classes had the onResume() method. In Flutter widgets this is missing. This library offers void onVisibilityChanged(WidgetVisibility visibility) to do something similar.

Features

Notice when:

  • the app is put in the background or brought out of the background
  • the widget initially becomes visible
  • the widget becomes invisible (a new page is pushed)
  • the widget is removed from stack
  • the widget becomes visible again (e.g. back button on Android is pressed)

Close the current screen via finish() like in Android.

Check if the widget is currently visible using bool isVisible().

Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  visibility_aware_state: <latest_version>

In your library add the following import:

import 'package:visibility_aware_state/visibility_aware_state.dart';

For help getting started with Flutter, view the online documentation.

Example

class Example extends StatefulWidget {
  @override
  _ExampleState createState() => _ExampleState();
}

class _ExampleState extends VisibilityAwareState<Example> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Example app'),
      ),
      body: Center(
        child: Text('Welcome to visibility_aware_state example app.'),
      ),
    );
  }

  @override
  void onVisibilityChanged(WidgetVisibility visibility) {
    // TODO: Use visibility
    super.onVisibilityChanged(visibility);
  }
}

Here is a specific example where the visibility is used for screen view tracking:

import 'package:flutter/widgets.dart';
import 'package:visibility_aware_state/visibility_aware_state.dart';

import 'tracker.dart';

abstract class ScreenState<T extends StatefulWidget>
    extends VisibilityAwareState<T> with Screen {

  @override
  void onVisibilityChanged(WidgetVisibility visibility) {
    if (visibility == WidgetVisibility.VISIBLE) {
      Tracker().trackScreen(this);
    }
    super.onVisibilityChanged(visibility);
  }

  @override
  String screenName() {
    return runtimeType.toString();
  }

}

mixin Screen {

  String screenName();

}

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue. If you fixed a bug or implemented a new feature, please send a pull request.

카테고리

소스 저장소

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

아직 데이터가 없습니다.