パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.0.5

visibility_aware_state

その可視性を認識している StatefulWidgets の状態。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1140
いいね数
34
Pub ポイント
150

パッケージをインストール

flutter pub add visibility_aware_state

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Flutterパッケージで、StatefulWidgetを拡張してウィジェットの可視性に基づいて状態を管理します。ウィジェットがビューポート内で表示または非表示になったときに自動的に検出でき、効率的なリソース管理と最適化されたパフォーマンスを可能にします。アニメーション、動画再生、データ取得など、ユーザーがウィジェットを確認できる場合にのみ実行すべき処理に最適です。既存のStatefulWidgetsに大きなコード変更なしにシームレスに統合できます。

用途

  • 可視性に基づいたアニメーションの最適化
  • 動画またはオーディオの再生を管理する
  • 遅延読み込みコンテンツ
  • 非表示ウィジェットのCPU使用量を削減する
  • スクロールベースのトリガーの処理

主な機能

  • 自動可視性検出
  • 最小限のボイラープレート
  • 既存の StatefulWidgets と互換性があります
  • すべての主要プラットフォームをサポートしています
  • 効率的なリソース管理

適している対象

  • アプリのパフォーマンスを最適化する開発者
  • スクロール可能なリストまたはカルーセルを備えたアプリ
  • メディア重視のアプリケーション
  • 遅延読み込みが必要なアプリ

注意事項

  • 複雑なネストされたレイアウトでは期待通りに動作しない可能性があります
  • カスタムレンダーオブジェクトでは注意が必要です
  • ビューポート内でのみ表示可能
  • UI以外の状態追跡には適していません
  • 正しい Widget ツリー構造に依存する

元の 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.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。