TapLatch

A small Flutter button that prevents repeated taps while an async callback is running. Supports a spinner, success cooldown, custom style, and error handling.

This is starter source code. Package name availability and publishing status have not been verified.

Try the example

cd example
flutter create . --platforms=web
flutter pub get
flutter run -d chrome

For the core package tests:

flutter pub get
flutter analyze
flutter test
flutter pub publish --dry-run

Use locally in another Flutter application

In your app's pubspec.yaml:

dependencies:
  taplatch:
    path: ../taplatch

Then:

import 'package:taplatch/taplatch.dart';

TapLatchButton(
  label: 'Book Now',
  loadingLabel: 'Booking...',
  cooldown: const Duration(seconds: 2),
  onPressed: () async {
    await bookingService.createBooking();
  },
  onSuccess: () {
    // Show success feedback.
  },
  onError: (error, stackTrace) {
    // Show failure feedback.
  },
)

bookingService in the snippet represents your own application's service, not a bundled API.

Options

Property Type Purpose
label String Button text
onPressed Future<void> Function() Protected async operation
loadingLabel String? Text during loading
icon Widget? Idle icon
loader Widget? Custom loading widget
style ButtonStyle? ElevatedButton style
enabled bool External enabled flag
cooldown Duration Delay further taps after success
onSuccess VoidCallback? Completion callback
onError void Function(Object, StackTrace)? Error callback

Important: TapLatch only prevents duplicate taps in this widget instance. For real bookings, orders, and payments, enforce idempotency and reconciliation on the server as well. Do not put private API credentials in a package published to pub.dev.

Publishing

  1. Confirm package name availability on https://pub.dev.
  2. Add your real repository/homepage links to pubspec.yaml if available.
  3. Ensure LICENSE, README.md, and CHANGELOG.md are correct.
  4. Run flutter analyze, flutter test, flutter pub publish --dry-run.
  5. If checks pass, run flutter pub publish.

Libraries

main
taplatch