From 7f56434ad63333bcc44bb2887129937c2765686f Mon Sep 17 00:00:00 2001 From: steven12138 Date: Fri, 15 Mar 2024 15:29:46 +0800 Subject: [PATCH] =?UTF-8?q?[fea]=20=E5=AF=BC=E8=88=AA=E6=A0=8F=E6=8B=96?= =?UTF-8?q?=E6=8B=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/settings/general_setting_page.dart | 35 +++++++++++- lib/commons/preferences/common_prefs.dart | 5 +- lib/home/view/wpy_page.dart | 54 ++++++++++++++----- 3 files changed, 79 insertions(+), 15 deletions(-) diff --git a/lib/auth/view/settings/general_setting_page.dart b/lib/auth/view/settings/general_setting_page.dart index 6c17b183..6ca11122 100644 --- a/lib/auth/view/settings/general_setting_page.dart +++ b/lib/auth/view/settings/general_setting_page.dart @@ -230,7 +230,40 @@ class _GeneralSettingPageState extends State { ), ), ), - + SizedBox(height: 10.h), + Container( + padding: EdgeInsets.fromLTRB(20.w, 10.h, 15.w, 10.h), + decoration: BoxDecoration( + color: + WpyTheme.of(context).get(WpyColorKey.primaryBackgroundColor), + borderRadius: BorderRadius.circular(12.r), + ), + child: WButton( + onPressed: () { + CommonPreferences.fastJumpOrder.value = "[]"; + }, + child: Row( + children: [ + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('重置导航栏顺序', style: mainTextStyle), + SizedBox(height: 3.h), + Text("恢复默认导航栏", style: hintTextStyle) + ], + ), + ), + Icon(Icons.restore, + color: WpyTheme.of(context) + .get(WpyColorKey.oldListActionColor), + size: 22), + SizedBox(width: 15.w), + ], + ), + ), + ), // SizedBox(height: 10.h), // Container( // padding: EdgeInsets.fromLTRB(20.w, 10.h, 15.w, 10.h), diff --git a/lib/commons/preferences/common_prefs.dart b/lib/commons/preferences/common_prefs.dart index 2ae669f1..ef6d039a 100644 --- a/lib/commons/preferences/common_prefs.dart +++ b/lib/commons/preferences/common_prefs.dart @@ -95,9 +95,12 @@ class CommonPreferences { static final useClassesBackend = PrefsBean('useClassesBackend', false); // 用后端爬虫代替前端爬虫(课表、考表、GPA) static final appThemeId = PrefsBean('appThemeId', 'builtin_light'); - static final appDarkThemeId = PrefsBean('appDarkThemeId', 'builtin_dark'); + static final appDarkThemeId = + PrefsBean('appDarkThemeId', 'builtin_dark'); + /// 0 light 1 dark 2 auto static final usingDarkTheme = PrefsBean('usingDarkTheme', 0); + static final fastJumpOrder = PrefsBean('fastJumpOrder', "[]"); /// 自习室 static final loungeUpdateTime = PrefsBean('loungeUpdateTime'); diff --git a/lib/home/view/wpy_page.dart b/lib/home/view/wpy_page.dart index 7b9aebfc..d714c692 100644 --- a/lib/home/view/wpy_page.dart +++ b/lib/home/view/wpy_page.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; @@ -183,9 +184,10 @@ class WPYPageState extends State with SingleTickerProviderStateMixin { duration: Duration(milliseconds: 300), curve: Curves.easeIn, decoration: BoxDecoration( - gradient: WpyTheme.of(context).getGradient( showSchedule && !Platform.isWindows - ? WpyColorSetKey.primaryGradient - : WpyColorSetKey.gradientPrimaryBackground))), + gradient: WpyTheme.of(context).getGradient( + showSchedule && !Platform.isWindows + ? WpyColorSetKey.primaryGradient + : WpyColorSetKey.gradientPrimaryBackground))), SafeArea( bottom: false, child: Stack( @@ -323,40 +325,66 @@ class SliverCardsWidget extends StatelessWidget { @override Widget build(BuildContext context) { - Widget cardList = ListView.builder( - controller: controller, + //reorder cards based on common preferences + List cardOrder = + List.from(json.decode(CommonPreferences.fastJumpOrder.value)); + + final ordered_cards = cardOrder.length != 0 + ? List.generate(cards.length, (index) => cards[cardOrder[index]]) + : cards; + + Widget cardList = ReorderableListView.builder( + proxyDecorator: (Widget child, int index, Animation animation) { + return child; + }, scrollDirection: Axis.horizontal, padding: EdgeInsets.only(left: 16.h), physics: const BouncingScrollPhysics(), clipBehavior: Clip.none, - itemCount: cards.length, + itemCount: ordered_cards.length, itemBuilder: (context, i) { - if (cards[i].label == '北洋维基') { + if (ordered_cards[i].label == '北洋维基') { return WButton( + key: ValueKey(ordered_cards[i].route), onPressed: () async { - if (await canLaunchUrl(Uri.parse(cards[i].route))) { - await launchUrl(Uri.parse(cards[i].route), + if (await canLaunchUrl(Uri.parse(ordered_cards[i].route))) { + await launchUrl(Uri.parse(ordered_cards[i].route), mode: LaunchMode.externalApplication); } else { ToastProvider.error('请检查网络状态'); } }, - child: generateCard(context, cards[i]), + child: generateCard(context, ordered_cards[i]), ); } else { return WButton( + key: ValueKey(ordered_cards[i].route), onPressed: () { ///为预热失物招领添加了if条件,上线后去掉即可 - if (cards[i].route == "") { + if (ordered_cards[i].route == "") { ToastProvider.error('开发中 敬请期待!'); } else { - Navigator.pushNamed(context, cards[i].route); + Navigator.pushNamed(context, ordered_cards[i].route); } }, - child: generateCard(context, cards[i]), + child: generateCard(context, ordered_cards[i]), ); } }, + onReorder: (int oldIndex, int newIndex) { + if (newIndex > oldIndex) { + newIndex -= 1; + } + final CardBean item = ordered_cards.removeAt(oldIndex); + ordered_cards.insert(newIndex, item); + + // 1 2 3 4 5 -> 1 2 5 4 3 + if (cardOrder.length == 0) + cardOrder = List.generate(cards.length, (i) => i); + final temp = cardOrder.removeAt(oldIndex); + cardOrder.insert(newIndex, temp); + CommonPreferences.fastJumpOrder.value = json.encode(cardOrder); + }, ); return SizedBox(