function_filter 1.1.2 function_filter: ^1.1.2 copied to clipboard
A Dart library for function filtering utilities, providing tools for debouncing and throttling function executions based on time intervals.
import 'package:flutter/material.dart';
import 'package:function_filter/function_filter.dart';
void main() {
runApp(const MaterialApp(home: DemoApp()));
}
class DemoApp extends StatefulWidget {
const DemoApp({super.key});
@override
State<StatefulWidget> createState() => _DemoAppState();
}
class _DemoAppState extends State<DemoApp> {
var _counter = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
children: [
SizedBox(height: 100),
Text('$_counter'),
SizedBox(height: 50),
MaterialButton(
onPressed: () => FunctionFilter.debounce(
this,
const Duration(milliseconds: 500),
() {
setState(() {
++_counter;
});
},
),
child: Text('Debounce +1'),
),
SizedBox(height: 50),
MaterialButton(
onPressed: () => FunctionFilter.throttle(
this,
const Duration(milliseconds: 500),
() {
setState(() {
++_counter;
});
},
),
child: Text('Throttle +1'),
),
],
),
),
);
}
}