background_on_back 1.0.1 copy "background_on_back: ^1.0.1" to clipboard
background_on_back: ^1.0.1 copied to clipboard

Flutter plugin to handle backgound the app on pressing back button instead of quitting app.

background_on_back #

pub package

A Flutter plugin for Android that intercepts the system back button to move the application to the background instead of exiting/closing it.

🚀 Features #

  • Prevent App Exit: Keeps your app alive in the background when the user presses the back button.
  • Persistent State: Ideal for apps that need to maintain state (music players, GPS trackers, etc.) without a full restart.
  • Simple API: Trigger backgrounding with a single line of code.

📦 Installation #

Add background_on_back to your pubspec.yaml file:

dependencies:
  background_on_back: ^latest

🛠️ Usage #

In modern Flutter (3.12+), it is recommended to use the PopScope widget to handle back button events.

Implementation Example

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

  @override
  Widget build(BuildContext context) {
    return PopScope(
        canPop: false,
        onPopInvokedWithResult: (didPop, result) {
          if (didPop) return;
          BackgroundOnBack.pop();
        },
        child: Scaffold(
          appBar: AppBar(title: const Text('Homepage')),
          body: Center(child: Text('Hassle free solution for android BACK press')),
        ),
      );
  }
}

🤝 Contributing #

Contributions are welcome! If you find a bug or want to suggest a feature, please open an issue or submit a pull request. [Contribute].

📄 License #

Distributed under the MIT License. See [LICENSE] for more information.

Code Contributors #

Contributors

1
likes
150
points
46
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Flutter plugin to handle backgound the app on pressing back button instead of quitting app.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on background_on_back

Packages that implement background_on_back