mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-25 04:45:54 +08:00
committed by
GitHub
parent
acb3784071
commit
218e829fd4
94
lib/pages/setting/pages/bar_set.dart
Normal file
94
lib/pages/setting/pages/bar_set.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:PiliPlus/models/common/enum_with_label.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class BarSetPage extends StatefulWidget {
|
||||
const BarSetPage({super.key});
|
||||
|
||||
@override
|
||||
State<BarSetPage> createState() => _BarSetPageState();
|
||||
}
|
||||
|
||||
class _BarSetPageState extends State<BarSetPage> {
|
||||
late final List<EnumWithLabel> defaultBars;
|
||||
late final Map<int, int> barIndex;
|
||||
late final String key;
|
||||
late final String title;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Map<String, dynamic> args = Get.arguments;
|
||||
key = args['key'];
|
||||
title = args['title'] ?? '';
|
||||
defaultBars = List<EnumWithLabel>.from(args['defaultBars']);
|
||||
List<int>? bars = (GStorage.setting.get(key) as List?)?.cast();
|
||||
if (bars != null) {
|
||||
barIndex = {for (var (k, v) in bars.indexed) v: k};
|
||||
|
||||
// 对 tabData 进行排序
|
||||
defaultBars.sort((a, b) {
|
||||
final indexA = barIndex[a.index] ?? barIndex.length;
|
||||
final indexB = barIndex[b.index] ?? barIndex.length;
|
||||
return indexA.compareTo(indexB);
|
||||
});
|
||||
} else {
|
||||
barIndex = {for (var (k, v) in defaultBars.indexed) v.index: k};
|
||||
}
|
||||
}
|
||||
|
||||
void saveEdit() {
|
||||
List<int> sortedBar = defaultBars
|
||||
.where((i) => barIndex.containsKey(i.index))
|
||||
.map((i) => i.index)
|
||||
.toList();
|
||||
GStorage.setting.put(key, sortedBar);
|
||||
SmartDialog.showToast('保存成功,下次启动时生效');
|
||||
}
|
||||
|
||||
void onReorder(int oldIndex, int newIndex) {
|
||||
setState(() {
|
||||
if (newIndex > oldIndex) newIndex -= 1;
|
||||
defaultBars.insert(newIndex, defaultBars.removeAt(oldIndex));
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('$title编辑'),
|
||||
actions: [
|
||||
TextButton(onPressed: saveEdit, child: const Text('保存')),
|
||||
const SizedBox(width: 12)
|
||||
],
|
||||
),
|
||||
body: ReorderableListView(
|
||||
onReorder: onReorder,
|
||||
footer: SizedBox(
|
||||
height: MediaQuery.of(context).padding.bottom + 30,
|
||||
child: const Align(
|
||||
alignment: Alignment.centerRight, child: Text('*长按拖动排序 ')),
|
||||
),
|
||||
children: defaultBars
|
||||
.map((i) => CheckboxListTile(
|
||||
key: Key(i.label),
|
||||
value: barIndex.containsKey(i.index),
|
||||
onChanged: (bool? value) {
|
||||
if (value!) {
|
||||
barIndex[i.index] = -1;
|
||||
} else {
|
||||
barIndex.remove(i.index);
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
title: Text(i.label),
|
||||
secondary: const Icon(Icons.drag_indicator_rounded),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -257,11 +257,11 @@ class _ColorSelectPageState extends State<ColorSelectPage> {
|
||||
),
|
||||
IgnorePointer(
|
||||
child: NavigationBar(
|
||||
destinations: defaultNavigationBars
|
||||
destinations: NavigationBarType.values
|
||||
.map(
|
||||
(item) => NavigationDestination(
|
||||
icon: item['icon'],
|
||||
label: item['label'],
|
||||
icon: item.icon,
|
||||
label: item.label,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
import 'package:PiliPlus/models/common/home_tab_type.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
|
||||
class TabbarSetPage extends StatefulWidget {
|
||||
const TabbarSetPage({super.key});
|
||||
|
||||
@override
|
||||
State<TabbarSetPage> createState() => _TabbarSetPageState();
|
||||
}
|
||||
|
||||
class _TabbarSetPageState extends State<TabbarSetPage> {
|
||||
late List defaultTabs;
|
||||
late List<String> tabbarSort;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
defaultTabs = homeTabsConfig;
|
||||
tabbarSort = GStorage.tabbarSort;
|
||||
// 对 tabData 进行排序
|
||||
defaultTabs.sort((a, b) {
|
||||
int indexA = tabbarSort.indexOf((a['type'] as HomeTabType).name);
|
||||
int indexB = tabbarSort.indexOf((b['type'] as HomeTabType).name);
|
||||
|
||||
// 如果类型在 sortOrder 中不存在,则放在末尾
|
||||
if (indexA == -1) indexA = tabbarSort.length;
|
||||
if (indexB == -1) indexB = tabbarSort.length;
|
||||
|
||||
return indexA.compareTo(indexB);
|
||||
});
|
||||
}
|
||||
|
||||
void saveEdit() {
|
||||
List<String> sortedTabbar = defaultTabs
|
||||
.where((i) => tabbarSort.contains((i['type'] as HomeTabType).name))
|
||||
.map<String>((i) => (i['type'] as HomeTabType).name)
|
||||
.toList();
|
||||
GStorage.setting.put(SettingBoxKey.tabbarSort, sortedTabbar);
|
||||
SmartDialog.showToast('保存成功,下次启动时生效');
|
||||
}
|
||||
|
||||
void onReorder(int oldIndex, int newIndex) {
|
||||
setState(() {
|
||||
if (newIndex > oldIndex) {
|
||||
newIndex -= 1;
|
||||
}
|
||||
final tabsItem = defaultTabs.removeAt(oldIndex);
|
||||
defaultTabs.insert(newIndex, tabsItem);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final listTiles = [
|
||||
for (int i = 0; i < defaultTabs.length; i++) ...[
|
||||
CheckboxListTile(
|
||||
key: Key(defaultTabs[i]['label']),
|
||||
value:
|
||||
tabbarSort.contains((defaultTabs[i]['type'] as HomeTabType).name),
|
||||
onChanged: (bool? newValue) {
|
||||
String tabTypeId = (defaultTabs[i]['type'] as HomeTabType).name;
|
||||
if (!newValue!) {
|
||||
tabbarSort.remove(tabTypeId);
|
||||
} else {
|
||||
tabbarSort.add(tabTypeId);
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
title: Text(defaultTabs[i]['label']),
|
||||
secondary: const Icon(Icons.drag_indicator_rounded),
|
||||
)
|
||||
]
|
||||
];
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Tabbar编辑'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => saveEdit(), child: const Text('保存')),
|
||||
const SizedBox(width: 12)
|
||||
],
|
||||
),
|
||||
body: ReorderableListView(
|
||||
onReorder: onReorder,
|
||||
footer: SizedBox(
|
||||
height: MediaQuery.of(context).padding.bottom + 30,
|
||||
child: const Align(
|
||||
alignment: Alignment.centerRight, child: Text('*长按拖动排序 ')),
|
||||
),
|
||||
children: listTiles,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user