HoldDownButton constructor

HoldDownButton({
  1. Key? key,
  2. required Widget child,
  3. required VoidCallback onHoldDown,
  4. Duration longWait = const Duration(milliseconds: 600),
  5. Duration middleWait = const Duration(milliseconds: 400),
  6. Duration minWait = const Duration(milliseconds: 250),
  7. Duration holdWait = const Duration(milliseconds: 100),
})

Creates a HoldDownButton widget. Great to use when want to execute a function continuously when the button is hold.

  • Can be used to make any Widget execute a function periodically when it is hold down.
  • Curve/flow towards periodic function execution can be changed. (That is time between each initial function call can be customized.)
  • After a long press is detected, the onHoldDown function will be called immediately.

Implementation

HoldDownButton({
  super.key,
  required this.child,
  required this.onHoldDown,
  this.longWait = const Duration(milliseconds: 600),
  this.middleWait = const Duration(milliseconds: 400),
  this.minWait = const Duration(milliseconds: 250),
  this.holdWait = const Duration(milliseconds: 100),
})  : assert(
        (longWait.inMicroseconds >= middleWait.inMicroseconds) &&
            (middleWait.inMicroseconds >= minWait.inMicroseconds) &&
            (minWait.inMicroseconds >= holdWait.inMicroseconds),
        'Initial delays should follow a descending order.',
      ),
      assert(!holdWait.isNegative, 'holdWait cannot be negative.');