mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-30 04:58:41 +00:00
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:
@@ -46,6 +46,8 @@ class MainController extends GetxController
|
||||
late bool navSearchStreamDebounce = Pref.navSearchStreamDebounce;
|
||||
late final optTabletNav = Pref.optTabletNav;
|
||||
|
||||
late bool directExitOnBack = Pref.directExitOnBack;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -623,6 +623,17 @@ List<SettingsModel> get styleSettings => [
|
||||
subtitle: '删除或调换Navbar',
|
||||
leading: const Icon(Icons.toc_outlined),
|
||||
),
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.sw1tch,
|
||||
title: '返回时直接退出',
|
||||
subtitle: '开启后在主页任意tab按返回键都直接退出,关闭则先回到Navbar的第一个tab',
|
||||
leading: const Icon(Icons.exit_to_app_outlined),
|
||||
setKey: SettingBoxKey.directExitOnBack,
|
||||
defaultVal: false,
|
||||
onChanged: (value) {
|
||||
Get.find<MainController>().directExitOnBack = value;
|
||||
},
|
||||
),
|
||||
if (Platform.isAndroid)
|
||||
SettingsModel(
|
||||
settingsType: SettingsType.normal,
|
||||
|
||||
Reference in New Issue
Block a user