深色模式、首页设置页面和功能优化
This commit is contained in:
143
lib/services/get/discover_controller.dart
Normal file
143
lib/services/get/discover_controller.dart
Normal file
@@ -0,0 +1,143 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../controllers/shared_preferences_storage_controller.dart';
|
||||
import '../../constants/app_constants.dart';
|
||||
|
||||
class DiscoverController extends GetxController {
|
||||
var categories = <String>[].obs;
|
||||
var showTips = true.obs;
|
||||
var globalTipsEnabled = true.obs;
|
||||
var isDeveloperMode = false.obs;
|
||||
var isInitialized = false.obs;
|
||||
var currentTabIndex = 0.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
// 立即初始化分类,不等待异步操作
|
||||
updateCategories();
|
||||
// 异步加载开发者模式设置
|
||||
loadDeveloperMode();
|
||||
// 异步加载全局Tips开关设置
|
||||
loadGlobalTipsSetting();
|
||||
}
|
||||
|
||||
Future<void> loadGlobalTipsSetting() async {
|
||||
try {
|
||||
final isEnabled = await SharedPreferencesStorageController.getBool(
|
||||
'global_tips_enabled',
|
||||
defaultValue: true,
|
||||
);
|
||||
globalTipsEnabled.value = isEnabled;
|
||||
// 如果全局开关关闭,本地showTips也设置为false
|
||||
if (!isEnabled) {
|
||||
showTips.value = false;
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略错误,使用默认值
|
||||
globalTipsEnabled.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadDeveloperMode() async {
|
||||
try {
|
||||
final isEnabled = await SharedPreferencesStorageController.getBool(
|
||||
'developer_mode_enabled',
|
||||
defaultValue: false,
|
||||
);
|
||||
isDeveloperMode.value = isEnabled;
|
||||
// 更新分类(如果开发者模式状态改变)
|
||||
updateCategories();
|
||||
} catch (e) {
|
||||
// 忽略错误,使用默认值
|
||||
isDeveloperMode.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void updateCategories() {
|
||||
categories.value = ['分类', '热门', '搜索'];
|
||||
if (isDeveloperMode.value) {
|
||||
categories.value.add('活跃');
|
||||
}
|
||||
isInitialized.value = true;
|
||||
}
|
||||
|
||||
Future<void> refreshContent() async {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
Get.snackbar('提示', '内容已刷新');
|
||||
}
|
||||
|
||||
void toggleTips() {
|
||||
showTips.value = false;
|
||||
}
|
||||
|
||||
void likeContent(int index) {
|
||||
Get.snackbar('提示', '点赞了内容${index + 1}');
|
||||
}
|
||||
|
||||
void commentContent(int index) {
|
||||
Get.snackbar('提示', '评论了内容${index + 1}');
|
||||
}
|
||||
|
||||
void shareContent(int index) {
|
||||
Get.snackbar('提示', '分享了内容${index + 1}');
|
||||
}
|
||||
|
||||
void bookmarkContent(int index) {
|
||||
Get.snackbar('提示', '收藏了内容${index + 1}');
|
||||
}
|
||||
|
||||
void showContentDetails(BuildContext context, int index, String category) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('$category - 内容${index + 1}'),
|
||||
content: Text('这是$category分类下内容${index + 1}的详细信息。'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('关闭'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showMoreOptions(BuildContext context, int index) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.report),
|
||||
title: const Text('举报'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Get.snackbar('提示', '举报内容');
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.block),
|
||||
title: const Text('屏蔽用户'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Get.snackbar('提示', '屏蔽用户');
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.link),
|
||||
title: const Text('复制链接'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Get.snackbar('提示', '链接已复制');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user