Line data Source code
1 : import 'dart:async';
2 : import 'package:flutter/foundation.dart';
3 : import '../debouncer_config.dart';
4 :
5 : /// Abstract base class for all debounce strategies.
6 : ///
7 : /// Implement this to create a fully custom debounce behaviour and pass it
8 : /// to [Debouncer] via the [DebouncerStrategy] parameter.
9 : ///
10 : /// Example:
11 : /// ```dart
12 : /// class MyCustomStrategy extends DebouncerStrategy {
13 : /// @override
14 : /// void execute(
15 : /// VoidCallback action,
16 : /// DebouncerConfig config,
17 : /// Timer? currentTimer,
18 : /// void Function(Timer?) updateTimer,
19 : /// ) {
20 : /// currentTimer?.cancel();
21 : /// // your custom logic here
22 : /// }
23 : /// }
24 : /// ```
25 : abstract class DebouncerStrategy {
26 7 : const DebouncerStrategy();
27 :
28 : /// Called every time [Debouncer.run] is invoked.
29 : ///
30 : /// - [action] — the callback to (eventually) fire.
31 : /// - [config] — the active [DebouncerConfig].
32 : /// - [currentTimer] — the in-flight [Timer], if any (may be null or inactive).
33 : /// - [updateTimer] — call this to replace or clear the stored timer.
34 : void execute(
35 : VoidCallback action,
36 : DebouncerConfig config,
37 : Timer? currentTimer,
38 : void Function(Timer?) updateTimer,
39 : );
40 : }
|