diff --git a/lib/pages/setting/style_setting.dart b/lib/pages/setting/style_setting.dart index 7b47e5e1..987ad256 100644 --- a/lib/pages/setting/style_setting.dart +++ b/lib/pages/setting/style_setting.dart @@ -5,6 +5,7 @@ import 'package:pilipala/models/common/theme_type.dart'; import 'package:pilipala/utils/storage.dart'; import 'controller.dart'; +import 'widgets/switch_item.dart'; class StyleSetting extends StatefulWidget { const StyleSetting({super.key}); @@ -66,6 +67,12 @@ class _StyleSettingState extends State { ), ), ), + const SetSwitchItem( + title: 'iOS路由切换', + subTitle: 'iOS路由切换样式,需重启', + setKey: SettingBoxKey.iosTransition, + defaultVal: false, + ), ListTile( dense: false, onTap: () { diff --git a/lib/pages/setting/widgets/switch_item.dart b/lib/pages/setting/widgets/switch_item.dart index 3e41e9ee..1b2cc620 100644 --- a/lib/pages/setting/widgets/switch_item.dart +++ b/lib/pages/setting/widgets/switch_item.dart @@ -32,6 +32,15 @@ class _SetSwitchItemState extends State { val = Setting.get(widget.setKey, defaultValue: widget.defaultVal ?? false); } + void switchChange(value) { + val = value ?? !val; + Setting.put(widget.setKey, val); + if (widget.setKey == SettingBoxKey.autoUpdate && value == true) { + Utils.checkUpdata(); + } + setState(() {}); + } + @override Widget build(BuildContext context) { TextStyle titleStyle = Theme.of(context).textTheme.titleMedium!; @@ -41,9 +50,7 @@ class _SetSwitchItemState extends State { .copyWith(color: Theme.of(context).colorScheme.outline); return ListTile( enableFeedback: true, - onTap: () { - Setting.put(widget.setKey, !val); - }, + onTap: () => switchChange(null), title: Text(widget.title!, style: titleStyle), subtitle: widget.subTitle != null ? Text(widget.subTitle!, style: subTitleStyle) @@ -51,22 +58,16 @@ class _SetSwitchItemState extends State { trailing: Transform.scale( scale: 0.8, child: Switch( - thumbIcon: MaterialStateProperty.resolveWith( - (Set states) { - if (states.isNotEmpty && states.first == MaterialState.selected) { - return const Icon(Icons.done); - } - return null; // All other states will use the default thumbIcon. - }), - value: val, - onChanged: (value) { - val = value; - Setting.put(widget.setKey, value); - if (widget.setKey == SettingBoxKey.autoUpdate && value == true) { - Utils.checkUpdata(); - } - setState(() {}); - }), + thumbIcon: MaterialStateProperty.resolveWith( + (Set states) { + if (states.isNotEmpty && states.first == MaterialState.selected) { + return const Icon(Icons.done); + } + return null; // All other states will use the default thumbIcon. + }), + value: val, + onChanged: (val) => switchChange(val), + ), ), ); } diff --git a/lib/router/app_pages.dart b/lib/router/app_pages.dart index 74dce755..6ce0717e 100644 --- a/lib/router/app_pages.dart +++ b/lib/router/app_pages.dart @@ -1,4 +1,8 @@ +// ignore_for_file: must_be_immutable + +import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:hive/hive.dart'; import 'package:pilipala/pages/about/index.dart'; import 'package:pilipala/pages/blacklist/index.dart'; import 'package:pilipala/pages/dynamics/deatil/index.dart'; @@ -27,15 +31,20 @@ import 'package:pilipala/pages/video/detail/replyReply/index.dart'; import 'package:pilipala/pages/webview/index.dart'; import 'package:pilipala/pages/setting/index.dart'; import 'package:pilipala/pages/media/index.dart'; +import 'package:pilipala/utils/storage.dart'; + +Box setting = GStrorage.setting; +bool iosTransition = + setting.get(SettingBoxKey.iosTransition, defaultValue: false); class Routes { static final List getPages = [ // 首页(推荐) - GetPage(name: '/', page: () => const HomePage()), + CustomGetPage(name: '/', page: () => const HomePage()), // 热门 - GetPage(name: '/hot', page: () => const HotPage()), + CustomGetPage(name: '/hot', page: () => const HotPage()), // 视频详情 - GetPage(name: '/video', page: () => const VideoDetailPage()), + CustomGetPage(name: '/video', page: () => const VideoDetailPage()), // 图片预览 GetPage( name: '/preview', @@ -45,51 +54,74 @@ class Routes { showCupertinoParallax: false, ), // - GetPage(name: '/webview', page: () => const WebviewPage()), + CustomGetPage(name: '/webview', page: () => const WebviewPage()), // 设置 - GetPage(name: '/setting', page: () => const SettingPage()), + CustomGetPage(name: '/setting', page: () => const SettingPage()), // - GetPage(name: '/media', page: () => const MediaPage()), + CustomGetPage(name: '/media', page: () => const MediaPage()), // - GetPage(name: '/fav', page: () => const FavPage()), + CustomGetPage(name: '/fav', page: () => const FavPage()), // - GetPage(name: '/favDetail', page: () => const FavDetailPage()), + CustomGetPage(name: '/favDetail', page: () => const FavDetailPage()), // 稍后再看 - GetPage(name: '/later', page: () => const LaterPage()), + CustomGetPage(name: '/later', page: () => const LaterPage()), // 历史记录 - GetPage(name: '/history', page: () => const HistoryPage()), + CustomGetPage(name: '/history', page: () => const HistoryPage()), // 搜索页面 - GetPage(name: '/search', page: () => const SearchPage()), + CustomGetPage(name: '/search', page: () => const SearchPage()), // 搜索结果 - GetPage(name: '/searchResult', page: () => const SearchResultPage()), + CustomGetPage(name: '/searchResult', page: () => const SearchResultPage()), // 动态 - GetPage(name: '/dynamics', page: () => const DynamicsPage()), + CustomGetPage(name: '/dynamics', page: () => const DynamicsPage()), // 动态详情 - GetPage(name: '/dynamicDetail', page: () => const DynamicDetailPage()), + CustomGetPage( + name: '/dynamicDetail', page: () => const DynamicDetailPage()), // 关注 - GetPage(name: '/follow', page: () => const FollowPage()), + CustomGetPage(name: '/follow', page: () => const FollowPage()), // 粉丝 - GetPage(name: '/fan', page: () => const FansPage()), + CustomGetPage(name: '/fan', page: () => const FansPage()), // 直播详情 - GetPage(name: '/liveRoom', page: () => const LiveRoomPage()), + CustomGetPage(name: '/liveRoom', page: () => const LiveRoomPage()), // 用户中心 - GetPage(name: '/member', page: () => const MemberPage()), + CustomGetPage(name: '/member', page: () => const MemberPage()), // 二级回复 - GetPage(name: '/replyReply', page: () => const VideoReplyReplyPanel()), + CustomGetPage( + name: '/replyReply', page: () => const VideoReplyReplyPanel()), // 播放设置 - GetPage(name: '/playSetting', page: () => const PlaySetting()), + CustomGetPage(name: '/playSetting', page: () => const PlaySetting()), // 外观设置 - GetPage(name: '/styleSetting', page: () => const StyleSetting()), + CustomGetPage(name: '/styleSetting', page: () => const StyleSetting()), // 隐私设置 - GetPage(name: '/privacySetting', page: () => const PrivacySetting()), + CustomGetPage(name: '/privacySetting', page: () => const PrivacySetting()), // 其他设置 - GetPage(name: '/extraSetting', page: () => const ExtraSetting()), + CustomGetPage(name: '/extraSetting', page: () => const ExtraSetting()), // - GetPage(name: '/blackListPage', page: () => const BlackListPage()), - GetPage(name: '/colorSetting', page: () => const ColorSelectPage()), - GetPage(name: '/fontSizeSetting', page: () => const FontSizeSelectPage()), + CustomGetPage(name: '/blackListPage', page: () => const BlackListPage()), + CustomGetPage(name: '/colorSetting', page: () => const ColorSelectPage()), + CustomGetPage( + name: '/fontSizeSetting', page: () => const FontSizeSelectPage()), // 关于 - GetPage(name: '/about', page: () => const AboutPage()), + CustomGetPage(name: '/about', page: () => const AboutPage()), ]; } + +class CustomGetPage extends GetPage { + bool? fullscreen = false; + + CustomGetPage({ + name, + page, + this.fullscreen, + transitionDuration, + }) : super( + name: name, + page: page, + curve: Curves.linear, + transition: iosTransition ? Transition.cupertino : Transition.native, + showCupertinoParallax: false, + popGesture: false, + transitionDuration: transitionDuration, + fullscreenDialog: fullscreen != null && fullscreen, + ); +} diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 6d5ef4eb..a8d0507f 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -110,6 +110,7 @@ class SettingBoxKey { static const String defaultTextScale = 'textScale'; static const String dynamicColor = 'dynamicColor'; // bool static const String customColor = 'customColor'; // 自定义主题色 + static const String iosTransition = 'iosTransition'; // ios路由 } class LocalCacheKey {