mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-09 11:37:51 +08:00
opt bar set
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -47,9 +47,9 @@ class _HomePageState extends State<HomePage>
|
|||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: TabBar(
|
child: TabBar(
|
||||||
controller: _homeController.tabController,
|
controller: _homeController.tabController,
|
||||||
tabs: [
|
tabs: _homeController.tabs
|
||||||
for (var i in _homeController.tabs) Tab(text: i.label),
|
.map((e) => Tab(text: e.label))
|
||||||
],
|
.toList(),
|
||||||
isScrollable: true,
|
isScrollable: true,
|
||||||
dividerColor: Colors.transparent,
|
dividerColor: Colors.transparent,
|
||||||
dividerHeight: 0,
|
dividerHeight: 0,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:PiliPlus/common/widgets/pair.dart';
|
||||||
import 'package:PiliPlus/models/common/enum_with_label.dart';
|
import 'package:PiliPlus/models/common/enum_with_label.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -12,47 +13,48 @@ class BarSetPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _BarSetPageState extends State<BarSetPage> {
|
class _BarSetPageState extends State<BarSetPage> {
|
||||||
late final List<EnumWithLabel> defaultBars;
|
|
||||||
late final Map<int, int> barIndex;
|
|
||||||
late final String key;
|
late final String key;
|
||||||
late final String title;
|
late final String title;
|
||||||
|
late final List<Pair<EnumWithLabel, bool>> list;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
Map<String, dynamic> args = Get.arguments;
|
final Map<String, dynamic> args = Get.arguments;
|
||||||
key = args['key'];
|
key = args['key'];
|
||||||
title = args['title'] ?? '';
|
title = args['title'];
|
||||||
defaultBars = List<EnumWithLabel>.from(args['defaultBars']);
|
final List? cache = GStorage.setting.get(key);
|
||||||
List? bars = GStorage.setting.get(key);
|
list = (args['defaultBars'] as List<EnumWithLabel>)
|
||||||
if (bars != null) {
|
.map((e) => Pair(first: e, second: cache?.contains(e.index) ?? true))
|
||||||
barIndex = {for (var (k, v) in bars.indexed) v: k};
|
.toList();
|
||||||
|
if (cache != null && cache.isNotEmpty) {
|
||||||
// 对 tabData 进行排序
|
list.sort((a, b) {
|
||||||
defaultBars.sort((a, b) {
|
final cacheIndex = {for (var (k, v) in cache.indexed) v: k};
|
||||||
final indexA = barIndex[a.index] ?? barIndex.length;
|
final indexA = cacheIndex[a.first.index] ?? cacheIndex.length;
|
||||||
final indexB = barIndex[b.index] ?? barIndex.length;
|
final indexB = cacheIndex[b.first.index] ?? cacheIndex.length;
|
||||||
return indexA.compareTo(indexB);
|
return indexA.compareTo(indexB);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
barIndex = {for (var (k, v) in defaultBars.indexed) v.index: k};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveEdit() {
|
void saveEdit() {
|
||||||
List<int> sortedBar = defaultBars
|
GStorage.setting.put(
|
||||||
.where((i) => barIndex.containsKey(i.index))
|
key,
|
||||||
.map((i) => i.index)
|
list.where((e) => e.second).map((e) => e.first.index).toList(),
|
||||||
.toList();
|
);
|
||||||
GStorage.setting.put(key, sortedBar);
|
|
||||||
SmartDialog.showToast('保存成功,下次启动时生效');
|
SmartDialog.showToast('保存成功,下次启动时生效');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onReset() {
|
||||||
|
Get.back();
|
||||||
|
GStorage.setting.delete(key);
|
||||||
|
SmartDialog.showToast('重置成功,下次启动时生效');
|
||||||
|
}
|
||||||
|
|
||||||
void onReorder(int oldIndex, int newIndex) {
|
void onReorder(int oldIndex, int newIndex) {
|
||||||
setState(() {
|
if (newIndex > oldIndex) newIndex -= 1;
|
||||||
if (newIndex > oldIndex) newIndex -= 1;
|
list.insert(newIndex, list.removeAt(oldIndex));
|
||||||
defaultBars.insert(newIndex, defaultBars.removeAt(oldIndex));
|
setState(() {});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -62,6 +64,7 @@ class _BarSetPageState extends State<BarSetPage> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('$title编辑'),
|
title: Text('$title编辑'),
|
||||||
actions: [
|
actions: [
|
||||||
|
TextButton(onPressed: onReset, child: const Text('重置')),
|
||||||
TextButton(onPressed: saveEdit, child: const Text('保存')),
|
TextButton(onPressed: saveEdit, child: const Text('保存')),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
],
|
],
|
||||||
@@ -77,20 +80,16 @@ class _BarSetPageState extends State<BarSetPage> {
|
|||||||
child: Text('*长按拖动排序'),
|
child: Text('*长按拖动排序'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
children: defaultBars
|
children: list
|
||||||
.map(
|
.map(
|
||||||
(i) => CheckboxListTile(
|
(e) => CheckboxListTile(
|
||||||
key: Key(i.label),
|
key: ValueKey(e.hashCode),
|
||||||
value: barIndex.containsKey(i.index),
|
value: e.second,
|
||||||
onChanged: (bool? value) {
|
onChanged: (bool? value) {
|
||||||
if (value!) {
|
e.second = value!;
|
||||||
barIndex[i.index] = -1;
|
|
||||||
} else {
|
|
||||||
barIndex.remove(i.index);
|
|
||||||
}
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
title: Text(i.label),
|
title: Text(e.first.label),
|
||||||
secondary: const Icon(Icons.drag_indicator_rounded),
|
secondary: const Icon(Icons.drag_indicator_rounded),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user