Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
* release/1.0.0:
  Modify SDK version
  Add package information
  Update badge
  Update README.md
  Create quick-import file
  Update example README.md
  Update README.md
  Repackaging library
  Update README.md Image
  Update CHANGELOG.md
  Update README.md
  Add screenshots
  add EasyThrottle example
  add EasyDebounce example
  add ListView to MainScreen
  add text style
  add fonts to example project
  add easy_debounce_throttle package to example project
  create easy throttle
  create easy debounce
  • Loading branch information
seosh817 committed Sep 2, 2022
2 parents 5c7e34d + fa3438a commit bea9ce0
Show file tree
Hide file tree
Showing 25 changed files with 716 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.0.5'
flutter-version: '3.0.0'
channel: 'stable'
- run: flutter --version
- run: flutter pub get
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## 0.0.1
## 1.0.0

* TODO: Describe initial release.
* Initial release.
203 changes: 178 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,192 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.

For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
<h1 align="center">Easy Debounce Throttle</h1>

For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->
<p align="center">
<a href="https://flutter.dev">
<img src="https://img.shields.io/badge/Platform-Flutter-02569B?logo=flutter"
alt="Platform" />
</a>
<a href="https://pub.dartlang.org/packages/easy_debounce_throttle">
<img src="https://img.shields.io/pub/v/easy_debounce_throttle.svg"
alt="Pub Package" />
</a>
<a href="https://github.com/seosh817/easy_debounce_throttle/actions/workflows/main.yml">
<img src="https://img.shields.io/github/workflow/status/seosh817/easy_debounce_throttle/main_workflow/release/1.0.0?logo=github"
alt="Build Status" />
</a>

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
<a href="https://opensource.org/licenses/MIT">
<img src="https://img.shields.io/github/license/seosh817/easy_debounce_throttle"
alt="License: MIT" />
</a>
</p><br>

## Features
<p align="center">An easy-to-use flutter package that provides debounce and throttle with Stream and WidgetBuilder.</p>

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started
## Usage

TODO: List prerequisites and provide or point to information on how to
start using the package.
If you want to subscribe to debounce, throttle events with Stream, use `EasyDebounce`, `EasyThrottle`

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


### EasyDebounce

```dart
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

```dart
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.

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
### EasyDebounceBuilder

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

## Additional information
### EasyThrottleBuilder

```dart
EasyThrottleBuilder(
delay: const Duration(milliseconds: 1000),
builder: (context, debounce) {
return TextButton(
onPressed: () => debounce(_increaseThrottleCount),
child: Text(
'increase debounce 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](https://github.com/seosh817/easy_debounce_throttle/tree/master/example)


| EasyDebounce | EasyThrottle |
|---|---|
|<img src="https://github.com/seosh817/easy_debounce_throttle/blob/release/1.0.0/screenshots/easy_debounce.gif?raw=true" width="300">| <img src="https://github.com/seosh817/easy_debounce_throttle/blob/release/1.0.0/screenshots/easy_throttle.gif?raw=true" width="300">|

| EasyDebounceBuilder | EasyThrottleBuilder |
|---|---|
|<img src="https://github.com/seosh817/easy_debounce_throttle/blob/release/1.0.0/screenshots/easy_debounce_builder.gif?raw=true" width="300">| <img src="https://github.com/seosh817/easy_debounce_throttle/blob/release/1.0.0/screenshots/easy_throttle_builder.gif?raw=true" width="300">|
## Installing

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
### 1. Depend on it

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

```yaml
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:

```dart
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.
```
17 changes: 1 addition & 16 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
# easy_debounce_throttle_example

A new Flutter project.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
# easy_debounce_throttle_example
Binary file added example/fonts/notosanskr_bold.otf
Binary file not shown.
Binary file added example/fonts/notosanskr_medium.otf
Binary file not shown.
Binary file added example/fonts/notosanskr_regular.otf
Binary file not shown.
121 changes: 121 additions & 0 deletions example/lib/example/debounce_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import 'package:easy_debounce_throttle/debounce/easy_debounce_builder.dart';
import 'package:easy_debounce_throttle/debounce/easy_debounce.dart';
import 'package:easy_debounce_throttle_example/util/text_style.dart';
import 'package:flutter/material.dart';

class DebounceExample extends StatefulWidget {
const DebounceExample({super.key});

@override
State<DebounceExample> createState() => _DebounceExampleState();
}

class _DebounceExampleState extends State<DebounceExample> {
final EasyDebounce _easyDebounce = EasyDebounce(delay: const Duration(milliseconds: 1000));
final TextEditingController _textController = TextEditingController();

int _debounceCount = 0;
String _debounceText = '';

void _increaseDebounceCount() async {
setState(() {
_debounceCount++;
});
}

@override
void initState() {
super.initState();
_textController.addListener(() {
_easyDebounce.debounce(_textController.text);
});
_easyDebounce.listen((data) {
setState(() {
_debounceText = '$data';
});
});
}

@override
void dispose() {
_easyDebounce.close();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('EasyDebounce Example', style: kNotoSansBold14.copyWith(color: Colors.white)),
// title: Text(widget.title),
),
body: SafeArea(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 8.0),
Text(
'debounce count: $_debounceCount',
style: kNotoSansBold14.copyWith(color: Colors.white),
textAlign: TextAlign.center,
),
EasyDebounceBuilder(
delay: const Duration(milliseconds: 1000),
builder: (context, debounce) {
return TextButton(
onPressed: () => debounce(_increaseDebounceCount),
child: Text(
'increase debounce count',
style: kNotoSansBold14.copyWith(color: Colors.white),
));
}),
const SizedBox(height: 40.0),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
controller: _textController,
keyboardType: TextInputType.name,
style: kNotoSansBold14.copyWith(color: Colors.white),
textInputAction: TextInputAction.next,
autofocus: false,
cursorColor: Colors.blue,
decoration: InputDecoration(
hintText: 'debounce',
hintStyle: kNotoSansBold14.copyWith(color: Colors.white.withAlpha(120)),
counterText: ' ',
focusedBorder: const UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
width: 1.5,
),
),
border: const UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
width: 1.0,
),
),
alignLabelWithHint: true,
isDense: true,
),
),
),
Text(
'text :',
style: kNotoSansBold14.copyWith(color: Colors.white),
textAlign: TextAlign.center,
),
Text(
_debounceText,
style: kNotoSansBold14.copyWith(color: Colors.white),
textAlign: TextAlign.center,
),
],
),
),
),
);
}
}
Loading

0 comments on commit bea9ce0

Please sign in to comment.