Files
wushu/lib/controllers/settings/suggestions.dart
Developer cba04235c8 release
2026-04-03 03:26:06 +08:00

584 lines
19 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../constants/app_constants.dart';
import '../../services/get/theme_controller.dart';
import '../../models/colors/app_colors.dart';
import '../../views/profile/theme/app-diy.dart';
import '../../views/footprint/collect_notes.dart';
import '../../views/profile/app-info.dart';
import '../../views/home/care/care-page.dart';
import '../../views/profile/guide/beginner_page.dart';
import '../../views/active/active_search_page.dart';
import '../../views/active/rate.dart';
import '../../views/profile/components/entire_page.dart';
class SuggestionsCard extends StatefulWidget {
const SuggestionsCard({super.key});
@override
State<SuggestionsCard> createState() => _SuggestionsCardState();
}
class _SuggestionsCardState extends State<SuggestionsCard> {
final ThemeController _themeController = Get.find<ThemeController>();
bool _showAlternativeContent = false;
final PageController _pageController = PageController();
int _currentPage = 0;
late List<Map<String, dynamic>> _actionItems;
@override
void initState() {
super.initState();
_shuffleActionItems();
}
/// 随机排序选项
void _shuffleActionItems() {
_actionItems = [
{
'title': '主题风格',
'subtitle': '自定义应用主题',
'icon': Icons.palette,
'page': const AppDiyPage(),
},
{
'title': '创建笔记',
'subtitle': '快速创建新笔记',
'icon': Icons.note_add,
'page': const CollectNotesPage(),
},
{
'title': '关怀模式',
'subtitle': '大字简洁模式',
'icon': Icons.favorite,
'page': const CarePage(),
},
{
'title': '使用教程',
'subtitle': '软件功能指南',
'icon': Icons.menu_book,
'page': const BeginnerPage(),
},
{
'title': '诗词搜索',
'subtitle': '全站诗词搜索',
'icon': Icons.search,
'page': const ActiveSearchPage(),
},
{
'title': '调试页面',
'subtitle': '活跃数据调试',
'icon': Icons.bug_report,
'page': const RatePage(),
},
{
'title': ' 搜索设置',
'subtitle': '搜索软件内的设置',
'icon': Icons.search,
'page': const _PlaceholderPage(title: '搜索设置'),
},
{
'title': '统计',
'subtitle': '全站数据统计',
'icon': Icons.bar_chart,
'page': const EntirePage(),
},
{
'title': '了解软件',
'subtitle': '查看应用信息',
'icon': Icons.info,
'page': const AppInfoPage(),
},
];
_actionItems.shuffle();
}
@override
void dispose() {
_pageController.dispose();
super.dispose();
}
/// 导航到页面并添加返回悬浮按钮
void _navigateToPage(Widget page) {
Get.to(() => _PageWithBackButton(child: page));
}
@override
Widget build(BuildContext context) {
return Obx(() {
final isDark = _themeController.isDarkModeRx.value;
final themeColor = AppColors.primary;
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: isDark ? 0.3 : 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
children: [
GestureDetector(
onTap: () {
setState(() {
_showAlternativeContent = !_showAlternativeContent;
});
},
child: Row(
children: [
Icon(Icons.settings_suggest, size: 40, color: themeColor),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'设置建议',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : Colors.black,
),
),
const SizedBox(height: 4),
Text(
_showAlternativeContent ? '是否在找,清理数据' : '是否在找,主题风格',
style: TextStyle(
fontSize: 13,
color: isDark ? Colors.grey[400] : Colors.grey[600],
),
),
],
),
),
GestureDetector(
onTap: () {
final nextPage = (_currentPage + 1) % 3;
_pageController.animateToPage(
nextPage,
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
);
},
child: Icon(Icons.refresh, color: themeColor),
),
],
),
),
const SizedBox(height: 16),
SizedBox(
height: 160,
child: PageView(
controller: _pageController,
onPageChanged: (index) {
setState(() {
_currentPage = index;
});
},
children: [
// 第一页随机排序后的前4个选项
Column(
children: [
Row(
children: [
Expanded(
child: _buildActionButton(
_actionItems[0]['title'],
_actionItems[0]['subtitle'],
_actionItems[0]['icon'],
() => _navigateToPage(_actionItems[0]['page']),
),
),
const SizedBox(width: 12),
Expanded(
child: _buildActionButton(
_actionItems[1]['title'],
_actionItems[1]['subtitle'],
_actionItems[1]['icon'],
() => _navigateToPage(_actionItems[1]['page']),
),
),
],
),
const SizedBox(height: 12),
Row(
children: [
Expanded(
child: _buildActionButton(
_actionItems[2]['title'],
_actionItems[2]['subtitle'],
_actionItems[2]['icon'],
() => _navigateToPage(_actionItems[2]['page']),
),
),
const SizedBox(width: 12),
Expanded(
child: _buildActionButton(
_actionItems[3]['title'],
_actionItems[3]['subtitle'],
_actionItems[3]['icon'],
() => _navigateToPage(_actionItems[3]['page']),
),
),
],
),
],
),
// 第二页随机排序后的中间4个选项
Column(
children: [
Row(
children: [
Expanded(
child: _buildActionButton(
_actionItems[4]['title'],
_actionItems[4]['subtitle'],
_actionItems[4]['icon'],
() => _navigateToPage(_actionItems[4]['page']),
),
),
const SizedBox(width: 12),
Expanded(
child: _buildActionButton(
_actionItems[5]['title'],
_actionItems[5]['subtitle'],
_actionItems[5]['icon'],
() => _navigateToPage(_actionItems[5]['page']),
),
),
],
),
const SizedBox(height: 12),
Row(
children: [
Expanded(
child: _buildActionButton(
_actionItems[6]['title'],
_actionItems[6]['subtitle'],
_actionItems[6]['icon'],
() => _navigateToPage(_actionItems[6]['page']),
),
),
const SizedBox(width: 12),
Expanded(
child: _buildActionButton(
_actionItems[7]['title'],
_actionItems[7]['subtitle'],
_actionItems[7]['icon'],
() => _navigateToPage(_actionItems[7]['page']),
),
),
],
),
],
),
// 第三页:最后一个选项
Column(
children: [
Row(
children: [
Expanded(
child: _buildActionButton(
_actionItems[8]['title'],
_actionItems[8]['subtitle'],
_actionItems[8]['icon'],
() => _navigateToPage(_actionItems[8]['page']),
),
),
const SizedBox(width: 12),
Expanded(child: Container()),
],
),
],
),
],
),
),
const SizedBox(height: 8),
// 页面指示器
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 8,
height: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _currentPage == 0
? themeColor
: (isDark ? Colors.grey[600] : Colors.grey[300]),
),
),
const SizedBox(width: 8),
Container(
width: 8,
height: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _currentPage == 1
? themeColor
: (isDark ? Colors.grey[600] : Colors.grey[300]),
),
),
const SizedBox(width: 8),
Container(
width: 8,
height: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _currentPage == 2
? themeColor
: (isDark ? Colors.grey[600] : Colors.grey[300]),
),
),
],
),
],
),
);
});
}
Widget _buildActionButton(
String title,
String subtitle,
IconData icon,
VoidCallback onTap,
) {
final isDark = _themeController.isDarkModeRx.value;
final themeColor = AppColors.primary;
return InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF333333) : const Color(0xFFF5F5F7),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: themeColor.withValues(alpha: 0.2),
width: 1,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: isDark ? Colors.white : Colors.black,
),
),
const SizedBox(height: 2),
Text(
subtitle,
style: TextStyle(
fontSize: 11,
color: isDark ? Colors.grey[400] : Colors.grey[600],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
const SizedBox(width: 8),
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: themeColor.withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(10),
),
child: Icon(icon, color: themeColor, size: 20),
),
],
),
),
);
}
}
/// 页面包装器 - 添加左侧返回悬浮按钮
class _PageWithBackButton extends StatefulWidget {
final Widget child;
const _PageWithBackButton({required this.child});
@override
State<_PageWithBackButton> createState() => _PageWithBackButtonState();
}
class _PageWithBackButtonState extends State<_PageWithBackButton> {
bool _showBackButton = true;
Timer? _hideTimer;
@override
void initState() {
super.initState();
_startHideTimer();
}
void _startHideTimer() {
_hideTimer?.cancel();
_hideTimer = Timer(const Duration(seconds: 5), () {
if (mounted) {
setState(() {
_showBackButton = false;
});
}
});
}
@override
void dispose() {
_hideTimer?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
final themeController = Get.find<ThemeController>();
return Obx(() {
final isDark = themeController.isDarkModeRx.value;
final themeColor = AppColors.primary;
return Scaffold(
body: Stack(
children: [
// 原始页面内容
widget.child,
// 左侧返回悬浮按钮
if (_showBackButton)
Positioned(
left: 0,
top: MediaQuery.of(context).size.height * 0.45,
child: GestureDetector(
onTap: () => Get.back(),
child: AnimatedOpacity(
opacity: _showBackButton ? 1.0 : 0.0,
duration: const Duration(milliseconds: 300),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 16,
),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(20),
bottomRight: Radius.circular(20),
),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(
alpha: isDark ? 0.4 : 0.15,
),
blurRadius: 8,
offset: const Offset(2, 0),
),
],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.arrow_back_ios,
color: themeColor,
size: 18,
),
const SizedBox(width: 4),
Text(
'返回',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: isDark ? Colors.white : Colors.black87,
),
),
],
),
),
),
),
),
],
),
);
});
}
}
/// 占位页面 - 用于清理数据功能
class _PlaceholderPage extends StatelessWidget {
final String title;
const _PlaceholderPage({required this.title});
@override
Widget build(BuildContext context) {
final themeController = Get.find<ThemeController>();
return Obx(() {
final isDark = themeController.isDarkModeRx.value;
final themeColor = AppColors.primary;
return Scaffold(
appBar: AppBar(
title: Text(title),
backgroundColor: isDark ? const Color(0xFF1A1A1A) : Colors.white,
foregroundColor: isDark ? Colors.white : Colors.black,
elevation: 0,
),
backgroundColor: isDark ? const Color(0xFF121212) : Colors.grey[50],
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.construction,
size: 64,
color: themeColor.withValues(alpha: 0.5),
),
const SizedBox(height: 16),
Text(
'$title 功能开发中',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: isDark ? Colors.white : Colors.black87,
),
),
const SizedBox(height: 8),
Text(
'敬请期待',
style: TextStyle(
fontSize: 14,
color: isDark ? Colors.grey[400] : Colors.grey[600],
),
),
],
),
),
);
});
}
}