Line data Source code
1 : import 'package:flutter/foundation.dart';
2 :
3 : /// Hooks that fire at key points in a [Debouncer]'s lifecycle.
4 : ///
5 : /// All callbacks are optional — supply only the ones you need.
6 : ///
7 : /// Example:
8 : /// ```dart
9 : /// final debouncer = Debouncer(
10 : /// delay: Duration(milliseconds: 300),
11 : /// hooks: LifecycleHooks(
12 : /// onFire: () => print('action fired'),
13 : /// onCancel: () => print('timer cancelled'),
14 : /// ),
15 : /// );
16 : /// ```
17 : class LifecycleHooks {
18 : /// Called just before the debounced action executes.
19 : final VoidCallback? onFire;
20 :
21 : /// Called when a pending timer is cancelled due to a new call arriving.
22 : final VoidCallback? onCancel;
23 :
24 : /// Called when [Debouncer.dispose] is invoked.
25 : final VoidCallback? onDispose;
26 :
27 1 : const LifecycleHooks({
28 : this.onFire,
29 : this.onCancel,
30 : this.onDispose,
31 : });
32 : }
|