https://github.com/fuadarradhi/double_back_to_close
Flutter package for request double back pressed before close app/route/screen.
https://github.com/fuadarradhi/double_back_to_close
back close flutter plugin to
Last synced: about 1 month ago
JSON representation
Flutter package for request double back pressed before close app/route/screen.
- Host: GitHub
- URL: https://github.com/fuadarradhi/double_back_to_close
- Owner: fuadarradhi
- License: mit
- Created: 2020-05-27T06:27:36.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-14T15:20:06.000Z (about 5 years ago)
- Last Synced: 2025-10-23T06:54:41.940Z (8 months ago)
- Topics: back, close, flutter, plugin, to
- Language: Dart
- Homepage: https://pub.dev/packages/double_back_to_close
- Size: 221 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# double_back_to_close
Flutter package for request double back pressed before close app/route/screen.

## Usage
Wrapping widget with DoubleBack where you want to use double back to close screen or app:
### Default (using TOAST)
```dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DoubleBack(
message:"Press back again to close",
child: Home(),
),
),
}
}
```
### Default (using TOAST) with optional style
```dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DoubleBack(
message:"Press back again to close",
child: Home(),
),
),
// optional style
textStyle: TextStyle(
fontSize: 13,
color: Colors.white,
),
background: Colors.red,
backgroundRadius: 30,
);
}
}
```
### Custom ( using snackbar for example)
```dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DoubleBack(
onFirstBackPress: (context) {
// you can use your custom here
// change this with your custom action
final snackBar = SnackBar(content: Text('Press back again to exit'));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
// ---
},
child: Home(),
),
);
}
}
```
### with custom delay
```dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DoubleBack(
onFirstBackPress: (context) {
Flushbar(
title: "Hey User",
message: "Press back again to exit",
duration: Duration(seconds: 15), // show 15 second flushbar
)..show(context);
},
child: Home(),
waitForSecondBackPress: 15, // wait for 15 second for second back pressed
),
);
}
}
```
### with custom condition
if you want to show message at spesific condition, for example, only show message if pageView at index 0.
```dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// Imagine that you are using materialbottom and only want to close when tabIndex = 0
home: DoubleBack(
condition: tabIndex == 0, // only show message when tabIndex=0
onConditionFail: (){
setState((){
tabIndex = 0; // if not 0, set pageview jumptopage 0
});
}
child: Home(),
),
);
}
}
```