Skip to content

Commit

Permalink
[fea] 导航栏拖拽
Browse files Browse the repository at this point in the history
  • Loading branch information
steven12138 committed Mar 15, 2024
1 parent 7f1d57f commit 7f56434
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 15 deletions.
35 changes: 34 additions & 1 deletion lib/auth/view/settings/general_setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,40 @@ class _GeneralSettingPageState extends State<GeneralSettingPage> {
),
),
),

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),
Expand Down
5 changes: 4 additions & 1 deletion lib/commons/preferences/common_prefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ class CommonPreferences {
static final useClassesBackend =
PrefsBean<bool>('useClassesBackend', false); // 用后端爬虫代替前端爬虫(课表、考表、GPA)
static final appThemeId = PrefsBean<String>('appThemeId', 'builtin_light');
static final appDarkThemeId = PrefsBean<String>('appDarkThemeId', 'builtin_dark');
static final appDarkThemeId =
PrefsBean<String>('appDarkThemeId', 'builtin_dark');

/// 0 light 1 dark 2 auto
static final usingDarkTheme = PrefsBean<int>('usingDarkTheme', 0);
static final fastJumpOrder = PrefsBean<String>('fastJumpOrder', "[]");

/// 自习室
static final loungeUpdateTime = PrefsBean<String>('loungeUpdateTime');
Expand Down
54 changes: 41 additions & 13 deletions lib/home/view/wpy_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -183,9 +184,10 @@ class WPYPageState extends State<WPYPage> 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(
Expand Down Expand Up @@ -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<int> 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<double> 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(
Expand Down

0 comments on commit 7f56434

Please sign in to comment.