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

パッケージ詳細v1.0.0+5

easy_debounce_throttle

Stream と WidgetBuilder を使用して、デバウンスおよびスロットリングを提供する使いやすい Flutter パッケージです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
6
いいね数
5
Pub ポイント
160

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

flutter pub add easy_debounce_throttle

パッケージ概要

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

ストリームおよびウィジェット用のデバウンスおよびスロットリング機能を簡素化する軽量なFlutterパッケージです。コールバックの実行を遅延または制限する直感的なメソッドを提供し、検索入力やリアルタイムフォームバリデーションなどのシナリオでのパフォーマンス向上を実現します。StreamおよびWidgetBuilderとシームレスに統合されており、FlutterのリアクティブUIフレームワーク内で簡単に利用できます。ボイラープレートコードなしでクリーンかつ再利用可能なロジックを求める開発者向けに設計されています。

用途

  • リアルタイム検索入力処理
  • 遅延付きのフォームフィールド検証
  • API呼び出しの頻度を低減する
  • ユーザー入力処理の最適化
  • ストリームベースのイベントスロットリング
  • UIの応答性の向上

主な機能

  • シンプルなデバウンスおよびスロットル API
  • ストリーム統合
  • WidgetBuilder のサポート
  • 最小限のボイラープレート
  • クロスプラットフォーム互換性
  • 洗練された、読みやすい構文

適している対象

  • インタラクティブなフォームを開発する開発者
  • 頻繁なユーザー入力のあるアプリ
  • パフォーマンスに敏感なUIコンポーネント
  • Flutterの初心者がリアクティブパターンを学ぶ
  • 保守性の高いコードを重視するチーム

注意事項

  • 高頻度・低レイテンシーイベントには適していません
  • Streams の理解が必要です
  • 基本的なデバウンス/スロットル以外のカスタマイズは限られている
  • 単純な使用ケースではわずかなオーバーヘッドが追加される可能性があります
  • 非同期操作や副作用と組み合わせて使用するのが最適です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Easy Debounce Throttle

Platform Pub Package Build Status License: MIT


An easy-to-use flutter package that provides debounce and throttle with Stream and WidgetBuilder.

Usage

If you want to subscribe to debounce, throttle events with Stream, use EasyDebounce, EasyThrottle

you should call the close() method to avoid memory leak

EasyDebounce
 final EasyDebounce _easyDebounce = EasyDebounce(delay: const Duration(milliseconds: 1000));
 final TextEditingController _textController = TextEditingController();
 
 @override
 void initState() {
 super.initState();
 _textController.addListener(() {
   _easyDebounce.debounce(_textController.text);
 });
 _easyDebounce.listen((data) {
   setState(() {
     _debounceText = '$data';
   });
 });
 }
 
 @override
 void dispose() {
 _easyDebounce.close();
 super.dispose();
}
EasyThrottle
 final EasyThrottle _easyThrottle = EasyThrottle(delay: const Duration(milliseconds: 1000));
 final TextEditingController _textController = TextEditingController();
 
 @override
 void initState() {
 super.initState();
 _textController.addListener(() {
   _easyThrottle.throttle(_textController.text);
 });
 _easyThrottle.listen((data) {
   setState(() {
     _throttleText = '$data';
   });
 });
 }
 
 @override
 void dispose() {
 _easyThrottle.close();
 super.dispose();
 }

If you want to receive debounce and throttle events from methods such as onPressed callbacks with WidgetBuilder, use EasyDebounceBuilder and EasyThrottleBuilder.

EasyDebounceBuilder and EasyThrottleBuilder internally disposes the stream, so there is no need to call the close() method.

EasyDebounceBuilder
EasyDebounceBuilder(
    delay: const Duration(milliseconds: 1000),
    builder: (context, debounce) {
      return TextButton(
          onPressed: () => debounce(() => _increaseDebounceCount()),
       // onPressed: () {
       //   debounce(() {
       //     _increaseDebounceCount();
       //   });
       // },
          child: Text(
            'increase debounce count',
            style: kNotoSansBold14.copyWith(color: Colors.white),
          ));
    }),
EasyThrottleBuilder
EasyThrottleBuilder(
    delay: const Duration(milliseconds: 1000),
    builder: (context, throttle) {
      return TextButton(
          onPressed: () => throttle(() => _increaseThrottleCount()),
       // onPressed: () {
       //   throttle(() {
       //     _increaseThrottleCount();
       //   });
       // },
          child: Text(
            'increase throttle count',
            style: kNotoSansBold14.copyWith(color: Colors.white),
          ));
    }),

Examples

An example can be found in the example directory of this repository.

A list of detailed examples can be found in this Examples Repository

EasyDebounce EasyThrottle
EasyDebounceBuilder EasyThrottleBuilder

Installing

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  easy_debounce_throttle: ^1.0.0

or

$ flutter pub add easy_debounce_throttle
2. Install it

You can install packages from the command line:

$ flutter pub get
3. Import it

Now in your Dart code, you can use:

import 'package:easy_debounce_throttle/easy_debounce_throttle.dart';

License

MIT License

Copyright (c) 2022 seosh817

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

カテゴリー

ソースリポジトリ

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

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