mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-02 00:58:19 +08: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 bool navSearchStreamDebounce = Pref.navSearchStreamDebounce;
|
||||||
late final optTabletNav = Pref.optTabletNav;
|
late final optTabletNav = Pref.optTabletNav;
|
||||||
|
|
||||||
|
late bool directExitOnBack = Pref.directExitOnBack;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
|||||||
@@ -159,6 +159,14 @@ class _MainAppState extends State<MainApp>
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onBack() {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
Utils.channel.invokeMethod('back');
|
||||||
|
} else {
|
||||||
|
SystemNavigator.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
@@ -166,15 +174,15 @@ class _MainAppState extends State<MainApp>
|
|||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
onPopInvokedWithResult: (bool didPop, Object? result) {
|
onPopInvokedWithResult: (bool didPop, Object? result) {
|
||||||
|
if (_mainController.directExitOnBack) {
|
||||||
|
onBack();
|
||||||
|
} else {
|
||||||
if (_mainController.selectedIndex.value != 0) {
|
if (_mainController.selectedIndex.value != 0) {
|
||||||
setIndex(0);
|
setIndex(0);
|
||||||
_mainController.bottomBarStream?.add(true);
|
_mainController.bottomBarStream?.add(true);
|
||||||
_homeController.searchBarStream?.add(true);
|
_homeController.searchBarStream?.add(true);
|
||||||
} else {
|
} else {
|
||||||
if (Platform.isAndroid) {
|
onBack();
|
||||||
Utils.channel.invokeMethod('back');
|
|
||||||
} else {
|
|
||||||
SystemNavigator.pop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -623,6 +623,17 @@ List<SettingsModel> get styleSettings => [
|
|||||||
subtitle: '删除或调换Navbar',
|
subtitle: '删除或调换Navbar',
|
||||||
leading: const Icon(Icons.toc_outlined),
|
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)
|
if (Platform.isAndroid)
|
||||||
SettingsModel(
|
SettingsModel(
|
||||||
settingsType: SettingsType.normal,
|
settingsType: SettingsType.normal,
|
||||||
|
|||||||
@@ -211,7 +211,8 @@ class SettingBoxKey {
|
|||||||
msgUnReadTypeV2 = 'msgUnReadTypeV2',
|
msgUnReadTypeV2 = 'msgUnReadTypeV2',
|
||||||
hiddenSettingUnlocked = 'hiddenSettingUnlocked',
|
hiddenSettingUnlocked = 'hiddenSettingUnlocked',
|
||||||
enableGradientBg = 'enableGradientBg',
|
enableGradientBg = 'enableGradientBg',
|
||||||
navBarSort = 'navBarSort';
|
navBarSort = 'navBarSort',
|
||||||
|
directExitOnBack = 'directExitOnBack';
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocalCacheKey {
|
class LocalCacheKey {
|
||||||
|
|||||||
@@ -719,4 +719,7 @@ class Pref {
|
|||||||
|
|
||||||
static bool get continuePlayInBackground =>
|
static bool get continuePlayInBackground =>
|
||||||
_setting.get(SettingBoxKey.continuePlayInBackground, defaultValue: false);
|
_setting.get(SettingBoxKey.continuePlayInBackground, defaultValue: false);
|
||||||
|
|
||||||
|
static bool get directExitOnBack =>
|
||||||
|
_setting.get(SettingBoxKey.directExitOnBack, defaultValue: false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user