feat: add configurable main page back behavior (#870)

* feat: add configurable main page back behavior

Add setting to control whether back button exits directly or returns to first tab

* update

---------

Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
6v
2025-06-26 11:40:44 +08:00
committed by GitHub
parent 0264a4c01f
commit 7886a901a3
5 changed files with 33 additions and 8 deletions

View File

@@ -159,6 +159,14 @@ class _MainAppState extends State<MainApp>
super.dispose();
}
void onBack() {
if (Platform.isAndroid) {
Utils.channel.invokeMethod('back');
} else {
SystemNavigator.pop();
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
@@ -166,15 +174,15 @@ class _MainAppState extends State<MainApp>
return PopScope(
canPop: false,
onPopInvokedWithResult: (bool didPop, Object? result) {
if (_mainController.selectedIndex.value != 0) {
setIndex(0);
_mainController.bottomBarStream?.add(true);
_homeController.searchBarStream?.add(true);
if (_mainController.directExitOnBack) {
onBack();
} else {
if (Platform.isAndroid) {
Utils.channel.invokeMethod('back');
if (_mainController.selectedIndex.value != 0) {
setIndex(0);
_mainController.bottomBarStream?.add(true);
_homeController.searchBarStream?.add(true);
} else {
SystemNavigator.pop();
onBack();
}
}
},