feat: 默认启动页设置 issues #483
This commit is contained in:
43
lib/models/common/nav_bar_config.dart
Normal file
43
lib/models/common/nav_bar_config.dart
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
const defaultNavigationBars = [
|
||||||
|
{
|
||||||
|
'id': 0,
|
||||||
|
'icon': Icon(
|
||||||
|
Icons.home_outlined,
|
||||||
|
size: 21,
|
||||||
|
),
|
||||||
|
'selectIcon': Icon(
|
||||||
|
Icons.home,
|
||||||
|
size: 21,
|
||||||
|
),
|
||||||
|
'label': "首页",
|
||||||
|
'count': 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 1,
|
||||||
|
'icon': Icon(
|
||||||
|
Icons.motion_photos_on_outlined,
|
||||||
|
size: 21,
|
||||||
|
),
|
||||||
|
'selectIcon': Icon(
|
||||||
|
Icons.motion_photos_on,
|
||||||
|
size: 21,
|
||||||
|
),
|
||||||
|
'label': "动态",
|
||||||
|
'count': 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 2,
|
||||||
|
'icon': Icon(
|
||||||
|
Icons.video_collection_outlined,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
'selectIcon': Icon(
|
||||||
|
Icons.video_collection,
|
||||||
|
size: 21,
|
||||||
|
),
|
||||||
|
'label': "媒体库",
|
||||||
|
'count': 0,
|
||||||
|
}
|
||||||
|
];
|
||||||
@ -12,6 +12,7 @@ import 'package:pilipala/pages/media/index.dart';
|
|||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
import 'package:pilipala/utils/utils.dart';
|
import 'package:pilipala/utils/utils.dart';
|
||||||
import '../../models/common/dynamic_badge_mode.dart';
|
import '../../models/common/dynamic_badge_mode.dart';
|
||||||
|
import '../../models/common/nav_bar_config.dart';
|
||||||
|
|
||||||
class MainController extends GetxController {
|
class MainController extends GetxController {
|
||||||
List<Widget> pages = <Widget>[
|
List<Widget> pages = <Widget>[
|
||||||
@ -19,44 +20,7 @@ class MainController extends GetxController {
|
|||||||
const DynamicsPage(),
|
const DynamicsPage(),
|
||||||
const MediaPage(),
|
const MediaPage(),
|
||||||
];
|
];
|
||||||
RxList navigationBars = [
|
RxList navigationBars = defaultNavigationBars.obs;
|
||||||
{
|
|
||||||
'icon': const Icon(
|
|
||||||
Icons.home_outlined,
|
|
||||||
size: 21,
|
|
||||||
),
|
|
||||||
'selectIcon': const Icon(
|
|
||||||
Icons.home,
|
|
||||||
size: 21,
|
|
||||||
),
|
|
||||||
'label': "首页",
|
|
||||||
'count': 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'icon': const Icon(
|
|
||||||
Icons.motion_photos_on_outlined,
|
|
||||||
size: 21,
|
|
||||||
),
|
|
||||||
'selectIcon': const Icon(
|
|
||||||
Icons.motion_photos_on,
|
|
||||||
size: 21,
|
|
||||||
),
|
|
||||||
'label': "动态",
|
|
||||||
'count': 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'icon': const Icon(
|
|
||||||
Icons.video_collection_outlined,
|
|
||||||
size: 20,
|
|
||||||
),
|
|
||||||
'selectIcon': const Icon(
|
|
||||||
Icons.video_collection,
|
|
||||||
size: 21,
|
|
||||||
),
|
|
||||||
'label': "媒体库",
|
|
||||||
'count': 0,
|
|
||||||
}
|
|
||||||
].obs;
|
|
||||||
final StreamController<bool> bottomBarStream =
|
final StreamController<bool> bottomBarStream =
|
||||||
StreamController<bool>.broadcast();
|
StreamController<bool>.broadcast();
|
||||||
Box setting = GStrorage.setting;
|
Box setting = GStrorage.setting;
|
||||||
@ -75,6 +39,10 @@ class MainController extends GetxController {
|
|||||||
Utils.checkUpdata();
|
Utils.checkUpdata();
|
||||||
}
|
}
|
||||||
hideTabBar = setting.get(SettingBoxKey.hideTabBar, defaultValue: true);
|
hideTabBar = setting.get(SettingBoxKey.hideTabBar, defaultValue: true);
|
||||||
|
int defaultHomePage =
|
||||||
|
setting.get(SettingBoxKey.defaultHomePage, defaultValue: 0) as int;
|
||||||
|
selectedIndex = defaultNavigationBars
|
||||||
|
.indexWhere((item) => item['id'] == defaultHomePage);
|
||||||
var userInfo = userInfoCache.get('userInfoCache');
|
var userInfo = userInfoCache.get('userInfoCache');
|
||||||
userLogin.value = userInfo != null;
|
userLogin.value = userInfo != null;
|
||||||
dynamicBadgeType.value = DynamicBadgeMode.values[setting.get(
|
dynamicBadgeType.value = DynamicBadgeMode.values[setting.get(
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import 'package:pilipala/utils/feed_back.dart';
|
|||||||
import 'package:pilipala/utils/login.dart';
|
import 'package:pilipala/utils/login.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
import '../../models/common/dynamic_badge_mode.dart';
|
import '../../models/common/dynamic_badge_mode.dart';
|
||||||
|
import '../../models/common/nav_bar_config.dart';
|
||||||
import '../main/index.dart';
|
import '../main/index.dart';
|
||||||
import 'widgets/select_dialog.dart';
|
import 'widgets/select_dialog.dart';
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ class SettingController extends GetxController {
|
|||||||
Rx<ThemeType> themeType = ThemeType.system.obs;
|
Rx<ThemeType> themeType = ThemeType.system.obs;
|
||||||
var userInfo;
|
var userInfo;
|
||||||
Rx<DynamicBadgeMode> dynamicBadgeType = DynamicBadgeMode.number.obs;
|
Rx<DynamicBadgeMode> dynamicBadgeType = DynamicBadgeMode.number.obs;
|
||||||
|
RxInt defaultHomePage = 0.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -40,6 +42,8 @@ class SettingController extends GetxController {
|
|||||||
dynamicBadgeType.value = DynamicBadgeMode.values[setting.get(
|
dynamicBadgeType.value = DynamicBadgeMode.values[setting.get(
|
||||||
SettingBoxKey.dynamicBadgeMode,
|
SettingBoxKey.dynamicBadgeMode,
|
||||||
defaultValue: DynamicBadgeMode.number.code)];
|
defaultValue: DynamicBadgeMode.number.code)];
|
||||||
|
defaultHomePage.value =
|
||||||
|
setting.get(SettingBoxKey.defaultHomePage, defaultValue: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
loginOut() async {
|
loginOut() async {
|
||||||
@ -110,4 +114,24 @@ class SettingController extends GetxController {
|
|||||||
SmartDialog.showToast('设置成功');
|
SmartDialog.showToast('设置成功');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置默认启动页
|
||||||
|
seteDefaultHomePage(BuildContext context) async {
|
||||||
|
int? result = await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return SelectDialog<int>(
|
||||||
|
title: '首页启动页',
|
||||||
|
value: defaultHomePage.value,
|
||||||
|
values: defaultNavigationBars.map((e) {
|
||||||
|
return {'title': e['label'], 'value': e['id']};
|
||||||
|
}).toList());
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (result != null) {
|
||||||
|
defaultHomePage.value = result;
|
||||||
|
setting.put(SettingBoxKey.defaultHomePage, result);
|
||||||
|
SmartDialog.showToast('设置成功,重启生效');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,10 +40,6 @@ class _TabbarSetPageState extends State<TabbarSetPage> {
|
|||||||
.where((i) => tabbarSort.contains((i['type'] as TabType).id))
|
.where((i) => tabbarSort.contains((i['type'] as TabType).id))
|
||||||
.map<String>((i) => (i['type'] as TabType).id)
|
.map<String>((i) => (i['type'] as TabType).id)
|
||||||
.toList();
|
.toList();
|
||||||
if (sortedTabbar.isEmpty) {
|
|
||||||
SmartDialog.showToast('请至少设置一项!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
settingStorage.put(SettingBoxKey.tabbarSort, sortedTabbar);
|
settingStorage.put(SettingBoxKey.tabbarSort, sortedTabbar);
|
||||||
SmartDialog.showToast('保存成功,下次启动时生效');
|
SmartDialog.showToast('保存成功,下次启动时生效');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import 'package:pilipala/utils/global_data.dart';
|
|||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
import '../../models/common/dynamic_badge_mode.dart';
|
import '../../models/common/dynamic_badge_mode.dart';
|
||||||
|
import '../../models/common/nav_bar_config.dart';
|
||||||
import 'controller.dart';
|
import 'controller.dart';
|
||||||
import 'widgets/switch_item.dart';
|
import 'widgets/switch_item.dart';
|
||||||
|
|
||||||
@ -29,7 +30,6 @@ class _StyleSettingState extends State<StyleSetting> {
|
|||||||
|
|
||||||
Box setting = GStrorage.setting;
|
Box setting = GStrorage.setting;
|
||||||
late int picQuality;
|
late int picQuality;
|
||||||
late double toastOpacity;
|
|
||||||
late ThemeType _tempThemeValue;
|
late ThemeType _tempThemeValue;
|
||||||
late dynamic defaultCustomRows;
|
late dynamic defaultCustomRows;
|
||||||
|
|
||||||
@ -37,7 +37,6 @@ class _StyleSettingState extends State<StyleSetting> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
picQuality = setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10);
|
picQuality = setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10);
|
||||||
toastOpacity = setting.get(SettingBoxKey.defaultToastOp, defaultValue: 1.0);
|
|
||||||
_tempThemeValue = settingController.themeType.value;
|
_tempThemeValue = settingController.themeType.value;
|
||||||
defaultCustomRows = setting.get(SettingBoxKey.customRows, defaultValue: 2);
|
defaultCustomRows = setting.get(SettingBoxKey.customRows, defaultValue: 2);
|
||||||
}
|
}
|
||||||
@ -267,6 +266,14 @@ class _StyleSettingState extends State<StyleSetting> {
|
|||||||
'当前主题:${colorSelectController.type.value == 0 ? '动态取色' : '指定颜色'}',
|
'当前主题:${colorSelectController.type.value == 0 ? '动态取色' : '指定颜色'}',
|
||||||
style: subTitleStyle)),
|
style: subTitleStyle)),
|
||||||
),
|
),
|
||||||
|
ListTile(
|
||||||
|
dense: false,
|
||||||
|
onTap: () => settingController.seteDefaultHomePage(context),
|
||||||
|
title: Text('默认启动页', style: titleStyle),
|
||||||
|
subtitle: Obx(() => Text(
|
||||||
|
'当前启动页:${defaultNavigationBars.firstWhere((e) => e['id'] == settingController.defaultHomePage.value)['label']}',
|
||||||
|
style: subTitleStyle)),
|
||||||
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
dense: false,
|
dense: false,
|
||||||
onTap: () => Get.toNamed('/fontSizeSetting'),
|
onTap: () => Get.toNamed('/fontSizeSetting'),
|
||||||
|
|||||||
@ -130,7 +130,8 @@ class SettingBoxKey {
|
|||||||
enableWordRe = 'enableWordRe',
|
enableWordRe = 'enableWordRe',
|
||||||
enableSearchWord = 'enableSearchWord',
|
enableSearchWord = 'enableSearchWord',
|
||||||
enableSystemProxy = 'enableSystemProxy',
|
enableSystemProxy = 'enableSystemProxy',
|
||||||
enableAi = 'enableAi';
|
enableAi = 'enableAi',
|
||||||
|
defaultHomePage = 'defaultHomePage';
|
||||||
|
|
||||||
/// 外观
|
/// 外观
|
||||||
static const String themeMode = 'themeMode',
|
static const String themeMode = 'themeMode',
|
||||||
|
|||||||
Reference in New Issue
Block a user