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

패키지 상세v1.0.0+5

easy_debounce_throttle

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.

카테고리

소스 저장소

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

아직 데이터가 없습니다.