flutter: Double back to close App

WAR fix #204: Going back leaves the app
Pressing the back button closes the application when you are
in Preferences or other sections, it's annoying.

Known Issues:
* String "Tap back again to leave." is not translated.
* Inability to perceive gestures.
This commit is contained in:
Calcitem 2021-05-23 13:24:17 +08:00
parent 308689726e
commit d1018abed9
4 changed files with 22 additions and 7 deletions

View File

@ -919,5 +919,9 @@
"atEnd": "At the end of move list.",
"@atEnd": {
"description": "At the end of move list."
},
"tapBackAgainToLeave": "Tap back again to leave.",
"@tapBackAgainToLeave": {
"description": "Tap back again to leave."
}
}

View File

@ -229,5 +229,6 @@
"notAIsTurn": "现在不是轮到电脑行棋",
"aiIsNotThinking": "电脑并非正在思考中",
"autoReplay": "自动回放",
"atEnd": "已经到底了"
"atEnd": "已经到底了",
"tapBackAgainToLeave": "再次按返回键退出应用"
}

View File

@ -20,6 +20,7 @@ import 'dart:async';
import 'dart:io';
import 'package:catcher/catcher.dart';
import 'package:double_back_to_close_app/double_back_to_close_app.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
@ -138,13 +139,21 @@ class _SanmillAppState extends State<SanmillApp> {
],
theme: ThemeData(primarySwatch: AppTheme.appPrimaryColor),
debugShowCheckedModeBanner: false,
home: WillPopScope(
onWillPop: () async {
Audios.disposePool();
return true;
},
child: NavigationHomeScreen(),
home: Scaffold(
body: DoubleBackToCloseApp(
child: NavigationHomeScreen(),
snackBar: const SnackBar(
content: Text('Tap back again to leave.'),
),
),
),
/*
WillPopScope(
onWillPop: () async {
Audios.disposePool();
return true;
},
*/
);
}
}

View File

@ -24,6 +24,7 @@ dependencies:
stack_trace: ^1.10.0
device_info_plus_platform_interface: ^1.0.1
devicelocale: ^0.4.1
double_back_to_close_app: ^2.0.1
dev_dependencies:
flutter_test: