hold_down_button 1.1.0 copy "hold_down_button: ^1.1.0" to clipboard
hold_down_button: ^1.1.0 copied to clipboard

A Flutter package to trigger an action repeatedly when a widget is hold/pressed down.

example/lib/main.dart

// Flutter Packages
import 'package:flutter/material.dart';

// This Package
import 'package:hold_down_button/hold_down_button.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.purple,
      ),
      darkTheme: ThemeData(
        brightness: Brightness.dark,
        primarySwatch: Colors.purple,
      ),
      themeMode: ThemeMode.dark,
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            const Divider(
              thickness: 2,
            ),
            HoldDownButton(
              onHoldDown: _incrementCounter,
              child: const Text('Text'),
            ),
            const Divider(
              thickness: 2,
            ),
            HoldDownButton(
              onHoldDown: _incrementCounter,
              longWait: const Duration(milliseconds: 1000),
              middleWait: const Duration(milliseconds: 600),
              minWait: const Duration(milliseconds: 300),
              child: ElevatedButton(
                onPressed: _incrementCounter,
                child: const Text('ElevatedButton'),
              ),
            ),
            const Divider(
              thickness: 2,
            ),
            HoldDownButton(
              onHoldDown: _incrementCounter,
              longWait: const Duration(milliseconds: 2000),
              middleWait: const Duration(milliseconds: 1500),
              minWait: const Duration(milliseconds: 1200),
              holdWait: const Duration(milliseconds: 1000),
              child: TextButton(
                onPressed: _incrementCounter,
                child: const Text('TextButton'),
              ),
            ),
            const Divider(
              thickness: 2,
            ),
            HoldDownButton(
              onHoldDown: _incrementCounter,
              longWait: const Duration(milliseconds: 100),
              middleWait: const Duration(milliseconds: 100),
              minWait: const Duration(milliseconds: 100),
              holdWait: const Duration(milliseconds: 100),
              child: InkWell(
                onTap: _incrementCounter,
                child: Ink(
                  width: 100,
                  height: 100,
                  color: Colors.red,
                  child: const Center(
                    child: Text('Ink & InkWell'),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: HoldDownButton(
        onHoldDown: _incrementCounter,
        child: FloatingActionButton(
          onPressed: _incrementCounter,
          child: const Icon(Icons.add),
        ),
      ),
    );
  }
}
6
likes
160
points
250
downloads

Publisher

verified publisheroutdatedguy.rocks

Weekly Downloads

A Flutter package to trigger an action repeatedly when a widget is hold/pressed down.

Homepage
Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on hold_down_button