double_back 0.0.3 copy "double_back: ^0.0.3" to clipboard
double_back: ^0.0.3 copied to clipboard

A Flutter utility widget for Android that prevents accidental app closure by requiring a double-tap on the system back button.

DoubleBackToCloseApp #

A lightweight and flexible Flutter widget for Android that prevents accidental app exits by requiring a double-tap on the back button.

Features #

  • Modern API: Uses PopScope (compatible with Flutter 3.16+).
  • Customizable: Provide your own UI feedback (SnackBar, Toast, or Lottie).
  • Conditional: Control exactly when the interceptor is active (e.g., only on the Home screen).
  • Platform Aware: Automatically disables itself on iOS/macOS to respect system gestures.

Installation #

Copy the double_back_to_close_app.dart file into your project or add it to your local packages.

Usage #

Simple Implementation #

DoubleBackToCloseApp(
  child: Scaffold(
    body: Center(child: Text("Home Screen")),
  ),
)
DoubleBackToCloseApp(
  canPopCondition: () => myRouter.currentPath == '/main',
  onFirstPop: (context) {
    // Trigger custom snackbar and haptic feedback
    HapticFeedback.lightImpact();
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text("Tap once more to leave")),
    );
  },
  child: const MainNavigator(),
)
1
likes
150
points
171
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter utility widget for Android that prevents accidental app closure by requiring a double-tap on the system back button.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on double_back