-
-
Save venkatd/7125882a8e86d80000ea4c2da2c2a8ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
class Debouncer { | |
final Duration delay; | |
Timer _timer; | |
Debouncer({this.delay}); | |
run(Function action) { | |
_timer?.cancel(); | |
_timer = Timer(delay, action); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to start | |
final _debouncer = Debouncer(delay: Duration(milliseconds: 250)); | |
// and later | |
onTextChange(String text) { | |
_debouncer.run(() => print(text)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@SAGARSURI, you can have something like this and call its dispose function from your user class.