import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../../controllers/shared_preferences_storage_controller.dart'; import '../../constants/app_constants.dart'; import 'theme_controller.dart'; class DiscoverController extends GetxController { var categories = [].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 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 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 refreshContent() async { await Future.delayed(const Duration(seconds: 1)); final themeController = Get.find(); Get.snackbar('提示', '内容已刷新', colorText: themeController.currentThemeColor); } 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('提示', '链接已复制'); }, ), ], ), ), ); } }