feat: #30 动态默认展示某项

This commit is contained in:
guozhigq
2023-08-24 21:31:19 +08:00
parent 6322b29aef
commit 5fc959eb59
4 changed files with 42 additions and 7 deletions

View File

@ -50,17 +50,21 @@ class DynamicsController extends GetxController {
},
];
bool flag = false;
RxInt initialValue = 1.obs;
RxInt initialValue = 0.obs;
Box userInfoCache = GStrorage.userInfo;
RxBool userLogin = false.obs;
var userInfo;
RxBool isLoadingDynamic = false.obs;
Box setting = GStrorage.setting;
@override
void onInit() {
userInfo = userInfoCache.get('userInfoCache');
userLogin.value = userInfo != null;
super.onInit();
initialValue.value =
setting.get(SettingBoxKey.defaultDynamicType, defaultValue: 0);
dynamicsType = DynamicsType.values[initialValue.value].obs;
}
Future queryFollowDynamic({type = 'init'}) async {
@ -99,7 +103,7 @@ class DynamicsController extends GetxController {
}
onSelectType(value) async {
dynamicsType.value = filterTypeList[value - 1]['value'];
dynamicsType.value = filterTypeList[value]['value'];
dynamicsList.value = [DynamicItemModel()];
page = 1;
initialValue.value = value;
@ -247,7 +251,7 @@ class DynamicsController extends GetxController {
void resetSearch() {
mid.value = -1;
dynamicsType.value = DynamicsType.values[0];
initialValue.value = 1;
initialValue.value = 0;
SmartDialog.showToast('还原默认加载');
dynamicsList.value = [DynamicItemModel()];
queryFollowDynamic();

View File

@ -132,7 +132,7 @@ class _DynamicsPageState extends State<DynamicsPage>
initialValue:
_dynamicsController.initialValue.value,
children: {
1: Text(
0: Text(
'全部',
style: TextStyle(
fontSize: Theme.of(context)
@ -140,19 +140,19 @@ class _DynamicsPageState extends State<DynamicsPage>
.labelMedium!
.fontSize),
),
2: Text('投稿',
1: Text('投稿',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelMedium!
.fontSize)),
3: Text('番剧',
2: Text('番剧',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelMedium!
.fontSize)),
4: Text('专栏',
3: Text('专栏',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/models/common/dynamics_type.dart';
import 'package:pilipala/models/common/reply_sort_type.dart';
import 'package:pilipala/utils/storage.dart';
@ -15,6 +16,7 @@ class ExtraSetting extends StatefulWidget {
class _ExtraSettingState extends State<ExtraSetting> {
Box setting = GStrorage.setting;
late dynamic defaultReplySort;
late dynamic defaultDynamicType;
@override
void initState() {
@ -22,6 +24,9 @@ class _ExtraSettingState extends State<ExtraSetting> {
// 默认优先显示最新评论
defaultReplySort =
setting.get(SettingBoxKey.replySortType, defaultValue: 0);
// 优先展示全部动态 all
defaultDynamicType =
setting.get(SettingBoxKey.defaultDynamicType, defaultValue: 0);
}
@override
@ -67,6 +72,31 @@ class _ExtraSettingState extends State<ExtraSetting> {
],
),
),
ListTile(
dense: false,
title: Text('动态展示', style: titleStyle),
subtitle: Text(
'当前优先展示「${DynamicsType.values[defaultDynamicType].labels}',
style: subTitleStyle,
),
trailing: PopupMenuButton(
initialValue: defaultDynamicType,
icon: const Icon(Icons.more_vert_outlined, size: 22),
onSelected: (item) {
defaultDynamicType = item;
setting.put(SettingBoxKey.defaultDynamicType, item);
setState(() {});
},
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
for (var i in DynamicsType.values) ...[
PopupMenuItem(
value: i.index,
child: Text(i.labels),
),
]
],
),
),
const SetSwitchItem(
title: '检查更新',
subTitle: '每次启动时检查是否需要更新',

View File

@ -103,6 +103,7 @@ class SettingBoxKey {
/// 其他
static const String autoUpdate = 'autoUpdate';
static const String replySortType = 'replySortType';
static const String defaultDynamicType = 'defaultDynamicType';
/// 外观
static const String themeMode = 'themeMode';