Skip to content

Commit

Permalink
flutter: Double back to close App
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
calcitem committed May 23, 2021
1 parent 3086897 commit d1018ab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/ui/flutter_app/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
3 changes: 2 additions & 1 deletion src/ui/flutter_app/lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,6 @@
"notAIsTurn": "现在不是轮到电脑行棋",
"aiIsNotThinking": "电脑并非正在思考中",
"autoReplay": "自动回放",
"atEnd": "已经到底了"
"atEnd": "已经到底了",
"tapBackAgainToLeave": "再次按返回键退出应用"
}
21 changes: 15 additions & 6 deletions src/ui/flutter_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
},
*/
);
}
}
1 change: 1 addition & 0 deletions src/ui/flutter_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d1018ab

Please sign in to comment.