diff --git a/lib/pages/main/controller.dart b/lib/pages/main/controller.dart index 39441255c..a627ba00e 100644 --- a/lib/pages/main/controller.dart +++ b/lib/pages/main/controller.dart @@ -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(); diff --git a/lib/pages/main/view.dart b/lib/pages/main/view.dart index 0fa74b2a6..84f1036ee 100644 --- a/lib/pages/main/view.dart +++ b/lib/pages/main/view.dart @@ -159,6 +159,14 @@ class _MainAppState extends State 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 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(); } } }, diff --git a/lib/pages/setting/models/style_settings.dart b/lib/pages/setting/models/style_settings.dart index 0c34329f3..388bcba1f 100644 --- a/lib/pages/setting/models/style_settings.dart +++ b/lib/pages/setting/models/style_settings.dart @@ -623,6 +623,17 @@ List 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().directExitOnBack = value; + }, + ), if (Platform.isAndroid) SettingsModel( settingsType: SettingsType.normal, diff --git a/lib/utils/storage_key.dart b/lib/utils/storage_key.dart index 150f7976b..1f7135d8f 100644 --- a/lib/utils/storage_key.dart +++ b/lib/utils/storage_key.dart @@ -211,7 +211,8 @@ class SettingBoxKey { msgUnReadTypeV2 = 'msgUnReadTypeV2', hiddenSettingUnlocked = 'hiddenSettingUnlocked', enableGradientBg = 'enableGradientBg', - navBarSort = 'navBarSort'; + navBarSort = 'navBarSort', + directExitOnBack = 'directExitOnBack'; } class LocalCacheKey { diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index 46f2351be..67a66be77 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -719,4 +719,7 @@ class Pref { static bool get continuePlayInBackground => _setting.get(SettingBoxKey.continuePlayInBackground, defaultValue: false); + + static bool get directExitOnBack => + _setting.get(SettingBoxKey.directExitOnBack, defaultValue: false); }