Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/byteszero/flutter_close_app

A simple and flexible Flutter close app plugin,(Android press 2 times to return to close, MacOS, iOS, Windows, Linux one-click close)一款灵活的 Flutter 关闭 App 插件,包含Android 按2次返回关闭,MacOS、iOS、Windows、Linux 一键关闭)
https://github.com/byteszero/flutter_close_app

close flutter simple

Last synced: 4 days ago
JSON representation

A simple and flexible Flutter close app plugin,(Android press 2 times to return to close, MacOS, iOS, Windows, Linux one-click close)一款灵活的 Flutter 关闭 App 插件,包含Android 按2次返回关闭,MacOS、iOS、Windows、Linux 一键关闭)

Awesome Lists containing this project

README

        


A simple and flexible Flutter close app plugin

(Android press 2 times to return to close, MacOS, iOS, Windows, Linux one-click close)







- [中文说明](https://github.com/yy1300326388/flutter_close_app/tree/master/README_CN.md)

## Feature

- ✅ Press back 2 times to close app
- ✅ Custom time interval
- ✅ Customize the prompt message
- ✅ Customize matching conditions
- ✅ Support Android
- ✅ One click to close app
- ✅ Support iOS
- ✅ Support MacOS
- ✅ Support Windows
- ✅ Support Linux
## Screenshot

![](https://github.com/yy1300326388/flutter_close_app/raw/master/example/images/example.gif)

## Use

- Dependent

``` shell
flutter pub add flutter_close_app
```
- Or

``` ymal
dependencies:
flutter_close_app: ^1.0.0
```

- Import package
``` dart
import 'package:flutter_close_app/flutter_close_app.dart';
```

## Example

- Press back 2 times to close app

``` dart
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return FlutterCloseAppPage(
onCloseFailed: () {
// Condition does not match: the first press or the second press interval is more than 2 seconds, display a prompt message
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Press again to exit 🎉'),
));
},
child: Scaffold(
appBar: AppBar(),
body: ...
),
);
}
}
```

- One click to close app

``` dart
FlutterCloseApp.close();
```

- Advanced usage

``` dart
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return FlutterCloseAppPage(
+ interval: 3, // Custom interval is 3 seconds
+ condition: tabIndex == 0, // Only close the app on the home page
onCloseFailed: () {
// Not the homepage does not prompt
+ if(tabIndex != 0) return;
// Condition does not match: the first press or the second press interval is more than 2 seconds, display a prompt message
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Press again to exit 🎉'),
));
},
child: Scaffold(
appBar: AppBar(),
body: ...
),
);
}
}
```

## Issues and feedback

Please file [issues](https://github.com/yy1300326388/flutter_close_app/issues) to send feedback or report a bug. Thank you!

## LICENSE

- [MIT](https://github.com/yy1300326388/flutter_close_app/blob/master/LICENSE)