Hold Down Button
A Flutter package to trigger an action repeatedly when a widget is hold/pressed down.
Features
HoldDownButton
displays the child widget passed to it and acts when it is pressed.- You can customize the time delay curve to make the button trigger action more or less quickly.
- Also you can set time delay for the periodic function call.
Getting started
Add to Dependencies
hold_down_button: ^1.1.0
Import the package
import 'package:hold_down_button/hold_down_button.dart';
Usage
Using the Widget with default values
HoldDownButton(
onHoldDown: () => print('Pressed'),
child: ElevatedButton(
onPressed: () => print('Pressed'),
child: const Text('ElevatedButton'),
),
),
Customizing initial delay curve
HoldDownButton(
onHoldDown: () => print('Pressed'),
longWait: const Duration(seconds: 1),
middleWait: const Duration(milliseconds: 750),
minWait: const Duration(milliseconds: 500),
child: ElevatedButton(
onPressed: () => print('Pressed'),
child: const Text('ElevatedButton'),
),
),
Changing the time delay for periodic function call
HoldDownButton(
onHoldDown: () => print('Pressed'),
holdWait: const Duration(milliseconds: 200),
child: ElevatedButton(
onPressed: () => print('Pressed'),
child: const Text('ElevatedButton'),
),
),
Description
Field | Description | Type | Default |
---|---|---|---|
child |
The child widget to be displayed. | Widget | - |
onHoldDown |
The callback to be called when the button is pressed. | VoidCallback | - |
holdWait |
The time delay for periodic function call. | Duration | const Duration(milliseconds: 100) |
longWait |
Time delay 2nd function call. | Duration | const Duration(milliseconds: 500) |
middleWait |
Time delay 3rd function call. | Duration | const Duration(milliseconds: 350) |
minWait |
Time delay 4th function call. | Duration | const Duration(milliseconds: 200) |
If you liked the package, then please give it a Like 👍🏼 and Star ⭐
Libraries
- A Flutter package to trigger an action repeatedly when a widget is hold/pressed down.