搜尋套件、儲存庫與 APP 分類

套件詳情v1.0.0+5

easy_debounce_throttle

一個容易使用的 Flutter 套件,提供帶有 Stream 和 WidgetBuilder 的防抖和節流功能。

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.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。