A Flutter package that allows Android users to press the back-button twice to close the app.

Overview

double_back_to_close_app

pub package ci workflow style: effective dart

A Flutter package that allows Android users to press the back-button twice to close the app.

Demo

Usage

Inside a Scaffold that wraps all your Widgets, place the DoubleBackToCloseApp passing a SnackBar:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: DoubleBackToCloseApp(
          child: Home(),
          snackBar: const SnackBar(
            content: Text('Tap back again to leave'),
          ),
        ),
      ),
    );
  }
}

Motivation

I've implemented such solution when I answered this question in Stack Overflow, and since this feature seems to be implemented very often, I decided to extract it in a lightweight library.

Comments
  • Add hideCurrentSnackBar for showing instantly

    Add hideCurrentSnackBar for showing instantly

    If diffrent snackBar is shown, DoubleBackToCloseApp.snackBar is not shown instantly.

    So, I want to add Scaffold.of(context).hideCurrentSnackBar() in _handleWillPop Function.

    opened by jja08111 7
  • Widget not working with flutter beta 1.24.0

    Widget not working with flutter beta 1.24.0

    Hey,

    I get this issue with flutter beta

    double_back_to_close_app.dart:91:30: Error: No named parameter with the name 'nullOk'. if (Scaffold.of(context, nullOk: true) == null) {

    opened by cedteg 5
  • NoSuchMethodError: The getter 'pressback' was called on null

    NoSuchMethodError: The getter 'pressback' was called on null

    My code: image My screen: image

    When I write the code: content: Text ("Press back again to exit",), that works. How do you use this in your application locales?

    opened by AlecSPb 3
  • Whenever I tap back button once, sanckbar appear

    Whenever I tap back button once, sanckbar appear

    Hello, thank you for your plugin

    I am trying to make a function to exit app when double tab the back button in the CupertinoTabbar.

    However, whenever I tap the back button, an exit message appeared.

    Hence I want to build a code work like following:

    • just tap back button once, return before pages
    • tap twice in few seconds, exit app.

    Is it possible to solve these problems using this plugin?

    I have also asked in the stackoverflow. Address of it is that:

    https://stackoverflow.com/questions/60587411/how-can-i-separate-one-tap-and-double-tap-of-back-button-in-flutter

    Thank you!

    opened by joun2001 3
  • Version solving failed

    Version solving failed

    I am getting this error when a try installing the latest this package as described here.

    Because myapp depends on double_back_to_close_app >=1.3.0-nullsafety.1 which requires SDK version >=2.12.0-0 <3.0.0, version solving failed. pub get failed (1; Because myapp depends on double_back_to_close_app >=1.3.0-nullsafety.1 which requires SDK version >=2.12.0-0 <3.0.0, version solving failed.) exit code 1

    I have already upgraded to the latest version of the flutter SDK.

    Running flutter doctor returns this

    [√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.17763.107], locale en-KE) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [!] Android Studio (version 4.1.0) X Flutter plugin not installed; this adds Flutter specific functionality. X Dart plugin not installed; this adds Dart specific functionality. [√] VS Code (version 1.52.1) [√] Connected device (1 available)

    Running flutter --version returns

    Flutter 1.22.5 • channel stable • https://github.com/flutter/flutter.git Framework • revision 7891006299 (3 weeks ago) • 2020-12-10 11:54:40 -0800 Engine • revision ae90085a84 Tools • Dart 2.10.4

    opened by King7Ace 2
  • what about this..

    what about this..

    WillPopScope( onWillPop: () async { if (exitAppTimer == null) { exitAppTimer = Timer(Duration(seconds: 3), () {}); AppToast().show(context, '${tr('ext_app_when_tap_again')}'); } else { if (exitAppTimer!.isActive) { exit(0); } else { exitAppTimer = Timer(Duration(seconds: 3), () {}); AppToast().show(context, '${tr('ext_app_when_tap_again')}'); } }

          return false;
        },
    
    opened by bakboem 1
  • App only closes on the first screen

    App only closes on the first screen

    I am pushing routes with Navigator to navigate between screens. I have written the package code in my third route. When I double back button press on the third route, it only takes me to my second route. It only works on the first route.

    Am I doing something wrong?

    opened by MustafaAdam 1
  • App closes if the snack bar was dismissed

    App closes if the snack bar was dismissed

    The app closes if the user taps the back-button, dismisses the snack bar and quickly taps the back-button again.

    This is happening because DoubleBackToCloseAppState.isSnackBarVisible considers the last time the back-button was tapped, not the actual snack bar's visibility.

    This behavior is arguably correct, though. However, I think this is not what the user expects, so I'm opening this issue.

    enhancement 
    opened by ghost 0
  • Possible solution with cupertinotabbar

    Possible solution with cupertinotabbar

    Hey,

    I'm using a CupertinoTabScaffold with 4 tabs and I've been trying to get this functionality to work with that. Any idea on how to support this feature? The problem I'm having is that the snackbar message is shown on all of the tabs that I have and the users can't exit the app because of that.

    opened by eripe970 3
  • Double click pops instead of exiting app...

    Double click pops instead of exiting app...

    So when I double press back, it just pops the page and directs to previous one.

    return Scaffold(
          appBar: const HomeAppBar(),
          bottomNavigationBar: const HomeNavigation(selectedIndex: 0,),
          body: DoubleBackToCloseApp(
            snackBar: const SnackBar(
              content: Text('Tap back again to leave'),
            ),
            child: SmartRefresher(
              enablePullDown: true,
              enablePullUp: true,
              child: _feedViews(),
              controller: _refreshController,
              onLoading: () => onLoading(formBloc, _refreshController),
              onRefresh: () => onRefresh(formBloc, _refreshController),
            ),
          ),
        );
    
    enhancement 
    opened by ssandr1kka 2
  • Widget not working

    Widget not working

    Hey, I tried using this package in my where I have already defined a function that displays a snack bar when called. That snack bar is working fine but your package is not doing anything. Rather the app is working the same it was working without your package.

    opened by harshkumarkhatri 1
Owner
Hugo Passos
w.wiki/j6C
Hugo Passos
Custom dropdown widget allows to add highly customizable widget in your projects with proper open and close animations and also comes with form required validation.

Custom Dropdown Custom Dropdown package lets you add customizable animated dropdown widget. Features Lots of properties to use and customize dropdown

Abdullah Chauhan 22 Dec 29, 2022
Rooftop - A photos and videos application which is able to show curated content from Pexel database on the press of a button

rooftop RoofTop is a photos and videos application which is able to show curated

null 2 Feb 7, 2022
Cupertino back gesture - Flutter package to set custom width of iOS back swipe gesture area

cupertino_back_gesture A Flutter package to set custom width of iOS back swipe gesture area. Usage To use this package, add cupertino_back_gesture as

null 28 Dec 7, 2022
Ali Türkay AVCI 1 Jan 20, 2022
Github-search - Allows users to search users on github Uses flutter

Github Search Github Search is a cross-platform mobile application powered by Flutter Framework and Github API. The application was built with simplic

Saul 3 Sep 13, 2022
This is a repository for Flutter Focused Menu, an easy to implement package for adding Focused Long Press Menu to Flutter Applications

Focused Menu This is an easy to implement package for adding Focused Long Press Menu to Flutter Applications Current Features Add Focused Menu to Any

Paras Jain 160 Dec 26, 2022
Flutter-context-menus - A flutter package to show context menus on right-click or long-press

context_menus A package to show context menus on right-click or long-press. ?? I

null 0 Jan 18, 2022
Flutter Image add drag sort, Image add drag sort, support click event, delete, add, long press drag sort.

flutter_image_add_drag_sort Flutter Image add drag sort, Image add drag sort, support click event, delete, add, long press drag sort, support video fi

null 5 Jun 23, 2020
Swipeable button view - Create Ripple Animated Pages With Swipeable Button View

swipeable_button_view You can create ripple animated pages with swipeable_button

cemreonur 3 Apr 22, 2022
Breathe is a mental health blogging app where users can join communities of doctors and other users from around the world and both share their problems as well as lend a ear to and help others

?????????????? ?????????????? In a condensed, suffocating society you can feel closed off, when you can't process your emotions and are going through

Soham Sen 3 May 16, 2022
This is flutter package for creating a gender selection widget which allows users to choose a gender with cool animations

gender_selection A Flutter package for gender selection. It is an aweome gender selection widget with cool gradients and animation effects Demo Instal

Rohan Malik 10 Apr 8, 2022
An app made using the Flutter framework that allows users to track information for over 1500 cryptocurrencies

Platypus Crypto Platypus Crypto is an ad-free cross-platform robust solution for tracking cryptocurrency assets. Our intuitive interface includes real

null 179 Jan 4, 2023
This plugin allows to kindly ask users to rate your app if custom conditions are met

Rate my app ! This plugin allows to kindly ask users to rate your app if custom conditions are met (eg. install time, number of launches, etc...). You

Hugo Delaunay 219 Dec 22, 2022
A flutter application that allows users to test their knowledge through quizzes made for specific topics.

Quiz_App A flutter application that allows users to test their knowledge through quizzes made for specific topics. Setup The application consists of a

null 0 Dec 29, 2021
Flutter form fields designed to take much of the burden of form-related coding off the programmer's back — masks, validations, keyboard type, etc.

well_formed Contents Overview Getting Started Demo application References Overview Well-Formed Widget Fields - Well-Formed - is a collection of Flutte

Dartoos 7 Nov 2, 2022
Flutter user authentication with back-end handler

user_auth Dart - Backend user auth helpe, with common methods Show some ❤️ and star the repo usage import package:user_auth/user_auth.dart. create ins

Mohamed Sayed 9 Jan 2, 2022
Bwo-master - An infinity procedural online game using Flutter and flames with NodeJS and Firebase for the back-end

Borderless World Online (BWO) An infinity procedural online game using Flutter a

null 17 Nov 29, 2022