关怀模式
This commit is contained in:
478
lib/views/home/care/care-page.dart
Normal file
478
lib/views/home/care/care-page.dart
Normal file
@@ -0,0 +1,478 @@
|
||||
/// 时间: 2026-04-02
|
||||
/// 功能: 关怀页面
|
||||
/// 介绍: 简约大字风格的关怀功能页面
|
||||
/// 最新变化: 2026-04-02 添加多个按钮和文本描述区域
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../services/get/theme_controller.dart';
|
||||
import '../../../services/get/care_controller.dart';
|
||||
|
||||
class CarePage extends StatefulWidget {
|
||||
const CarePage({super.key});
|
||||
|
||||
@override
|
||||
State<CarePage> createState() => _CarePageState();
|
||||
}
|
||||
|
||||
class _CarePageState extends State<CarePage> {
|
||||
final CareController _careController = Get.find<CareController>();
|
||||
bool _readAloudEnabled = false;
|
||||
final List<String> _options = ['诗词', '出处', '译文', '更多', '原文', '问候语'];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final themeController = Get.find<ThemeController>();
|
||||
final isDark = themeController.isDarkModeRx.value;
|
||||
final primaryColor = themeController.currentThemeColor;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: isDark ? const Color(0xFF121212) : Colors.white,
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
'关怀',
|
||||
style: TextStyle(
|
||||
color: isDark ? Colors.white : primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
backgroundColor: isDark ? const Color(0xFF1A1A1A) : Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: Icon(
|
||||
Icons.arrow_back,
|
||||
color: isDark ? Colors.white : primaryColor,
|
||||
),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.info_outline,
|
||||
color: isDark ? Colors.white : primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: isDark
|
||||
? const Color(0xFF2A2A2A)
|
||||
: Colors.white,
|
||||
title: Text(
|
||||
'功能说明',
|
||||
style: TextStyle(
|
||||
color: isDark ? Colors.white : Colors.black87,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
content: Text(
|
||||
'该功能处于开发状态,限时免费使用\n待后续开发完成后,使用需付费激活\n其他功能不受影响。',
|
||||
style: TextStyle(
|
||||
color: isDark ? Colors.grey[300] : Colors.grey[700],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('确定', style: TextStyle(color: primaryColor)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
children: [
|
||||
Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.people, size: 80, color: primaryColor),
|
||||
const SizedBox(width: 32),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'关怀',
|
||||
style: TextStyle(
|
||||
fontSize: 48,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isDark ? Colors.white : Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'用心呵护每一位用户',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
_buildCareModeToggle(isDark, primaryColor),
|
||||
const SizedBox(height: 24),
|
||||
_buildUserTypeSelector(isDark, primaryColor),
|
||||
const SizedBox(height: 24),
|
||||
_buildPinyinToggle(isDark, primaryColor),
|
||||
const SizedBox(height: 24),
|
||||
_buildMultiSelectOptions(isDark, primaryColor),
|
||||
const SizedBox(height: 24),
|
||||
_buildDescriptionArea(isDark),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCareModeToggle(bool isDark, Color primaryColor) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'关怀模式',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isDark ? Colors.white : Colors.black87,
|
||||
),
|
||||
),
|
||||
Obx(
|
||||
() => Switch(
|
||||
value: _careController.isCareModeEnabled,
|
||||
onChanged: (value) => _careController.toggleCareMode(),
|
||||
activeColor: primaryColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUserTypeSelector(bool isDark, Color primaryColor) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'用户类型',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isDark ? Colors.white : Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildUserTypeButton(
|
||||
'儿童',
|
||||
_careController.userType == '儿童',
|
||||
isDark,
|
||||
primaryColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: _buildUserTypeButton(
|
||||
'学生',
|
||||
_careController.userType == '学生',
|
||||
isDark,
|
||||
primaryColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF3A3A3A) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Obx(
|
||||
() => Text(
|
||||
_careController.userType == '儿童'
|
||||
? '儿童模式:大字体、简单界面、拼音辅助,适合低龄儿童使用。界面更加卡通化,内容简单易懂,帮助儿童轻松学习诗词。'
|
||||
: '学生模式:适中字体、学习辅助、诗词解析,适合学生群体使用。提供详细的诗词注释、背景知识,助力学生深入理解古典文学。',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
height: 1.5,
|
||||
color: isDark ? Colors.grey[300] : Colors.grey[700],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUserTypeButton(
|
||||
String label,
|
||||
bool isSelected,
|
||||
bool isDark,
|
||||
Color primaryColor,
|
||||
) {
|
||||
return GestureDetector(
|
||||
onTap: () => _careController.setUserType(label),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? primaryColor
|
||||
: (isDark ? const Color(0xFF3A3A3A) : Colors.white),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isSelected ? primaryColor : Colors.transparent,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: (isDark ? Colors.white : Colors.black87),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPinyinToggle(bool isDark, Color primaryColor) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'拼音显示',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isDark ? Colors.white : Colors.black87,
|
||||
),
|
||||
),
|
||||
Obx(
|
||||
() => Switch(
|
||||
value: _careController.pinyinEnabled,
|
||||
onChanged: (value) => _careController.setPinyinEnabled(value),
|
||||
activeColor: primaryColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'朗读',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isDark ? Colors.white : Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.info_outline,
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
size: 20,
|
||||
),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: isDark
|
||||
? const Color(0xFF2A2A2A)
|
||||
: Colors.white,
|
||||
title: Text(
|
||||
'功能说明',
|
||||
style: TextStyle(
|
||||
color: isDark ? Colors.white : Colors.black87,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
content: Text(
|
||||
'你使用的设备暂不支持朗读功能\n 等待上游厂商适配TTS.',
|
||||
style: TextStyle(
|
||||
color: isDark
|
||||
? Colors.grey[300]
|
||||
: Colors.grey[700],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(
|
||||
'确定',
|
||||
style: TextStyle(color: primaryColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
Switch(
|
||||
value: false,
|
||||
onChanged: null,
|
||||
activeColor: isDark ? Colors.grey[700] : Colors.grey[400],
|
||||
inactiveTrackColor: isDark
|
||||
? Colors.grey[800]
|
||||
: Colors.grey[300],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMultiSelectOptions(bool isDark, Color primaryColor) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'显示选项',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isDark ? Colors.white : Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Obx(
|
||||
() => Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 12,
|
||||
children: _options.map((option) {
|
||||
final isSelected = _careController.selectedOptions.contains(
|
||||
option,
|
||||
);
|
||||
final isPoetry = option == '诗词';
|
||||
return GestureDetector(
|
||||
onTap: isPoetry
|
||||
? null
|
||||
: () => _careController.toggleOption(option),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 12,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? primaryColor
|
||||
: (isDark ? const Color(0xFF3A3A3A) : Colors.white),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isSelected ? primaryColor : Colors.transparent,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (isSelected)
|
||||
Icon(Icons.check, color: Colors.white, size: 20),
|
||||
if (isSelected) const SizedBox(width: 8),
|
||||
Text(
|
||||
option,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: (isDark ? Colors.white : Colors.black87),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDescriptionArea(bool isDark) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'功能说明',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isDark ? Colors.white : Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'关怀模式为儿童和学生用户提供更加友好的界面体验。\n\n'
|
||||
'开启关怀模式后,应用将根据选择的用户类型自动调整界面显示。',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
height: 1.6,
|
||||
color: isDark ? Colors.grey[300] : Colors.grey[700],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
512
lib/views/home/care/care_poetry_page.dart
Normal file
512
lib/views/home/care/care_poetry_page.dart
Normal file
@@ -0,0 +1,512 @@
|
||||
/// 时间: 2026-04-02
|
||||
/// 功能: 关怀模式诗词页面
|
||||
/// 介绍: 关怀模式下显示的诗词页面,根据关怀设置显示不同内容
|
||||
/// 最新变化: 2026-04-02 初始创建
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../services/get/home_controller.dart';
|
||||
import '../../../services/get/theme_controller.dart';
|
||||
import '../../../services/get/care_controller.dart';
|
||||
import '../../../constants/app_constants.dart';
|
||||
import '../home_part.dart';
|
||||
import 'care_widgets.dart';
|
||||
import 'pinyin_helper.dart';
|
||||
|
||||
class CarePoetryPage extends StatefulWidget {
|
||||
const CarePoetryPage({super.key});
|
||||
|
||||
@override
|
||||
State<CarePoetryPage> createState() => _CarePoetryPageState();
|
||||
}
|
||||
|
||||
class _CarePoetryPageState extends State<CarePoetryPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
String _getTimeOfDayGreeting() {
|
||||
final hour = DateTime.now().hour;
|
||||
if (hour >= 5 && hour < 7) {
|
||||
return '清晨了,呼吸新鲜空气';
|
||||
} else if (hour >= 7 && hour < 9) {
|
||||
return '早上好,元气满满';
|
||||
} else if (hour >= 9 && hour < 12) {
|
||||
return '上午好,努力工作';
|
||||
} else if (hour >= 12 && hour < 14) {
|
||||
return '中午了,吃顿好的';
|
||||
} else if (hour >= 14 && hour < 17) {
|
||||
return '下午了,喝杯咖啡';
|
||||
} else if (hour >= 17 && hour < 19) {
|
||||
return '傍晚了,休息一下';
|
||||
} else if (hour >= 19 && hour < 22) {
|
||||
return '晚上好,放松身心';
|
||||
} else {
|
||||
return '深夜了,注意身体';
|
||||
}
|
||||
}
|
||||
|
||||
late AnimationController _animationController;
|
||||
late Animation<double> _fadeAnimation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_animationController = AnimationController(
|
||||
duration: const Duration(milliseconds: 500),
|
||||
vsync: this,
|
||||
);
|
||||
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(parent: _animationController, curve: Curves.easeOut),
|
||||
);
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final homeController = Get.find<HomeController>();
|
||||
final themeController = Get.find<ThemeController>();
|
||||
final careController = Get.find<CareController>();
|
||||
|
||||
return Obx(() {
|
||||
final isDark = themeController.isDarkModeRx.value;
|
||||
final primaryColor = themeController.currentThemeColor;
|
||||
final poetryData = homeController.poetryData.value;
|
||||
|
||||
if (poetryData == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
// 当诗词数据变化时,重新播放动画
|
||||
_animationController.reset();
|
||||
_animationController.forward();
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: isDark ? const Color(0xFF121212) : Colors.grey[50],
|
||||
body: SafeArea(
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
try {
|
||||
await homeController.loadNextPoetry();
|
||||
} catch (e) {
|
||||
print('加载诗词失败: $e');
|
||||
}
|
||||
},
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// 关怀模式开关
|
||||
CarePageHeaderToggle(isDark: isDark),
|
||||
const SizedBox(height: 16),
|
||||
// 问候语bar
|
||||
if (careController.selectedOptions.contains('问候语'))
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [primaryColor.withAlpha(204), primaryColor],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.wb_sunny, color: Colors.white, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_getTimeOfDayGreeting(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (careController.selectedOptions.contains('问候语'))
|
||||
const SizedBox(height: 16),
|
||||
// 出处
|
||||
if (careController.selectedOptions.contains('出处'))
|
||||
_buildPoetrySource(poetryData, isDark, primaryColor),
|
||||
if (careController.selectedOptions.contains('出处'))
|
||||
const SizedBox(height: 24),
|
||||
if (!careController.selectedOptions.contains('问候语') &&
|
||||
!careController.selectedOptions.contains('出处'))
|
||||
const SizedBox(height: 24),
|
||||
// 诗词标题
|
||||
if (careController.selectedOptions.contains('诗词'))
|
||||
_buildPoetryTitle(poetryData, isDark, primaryColor),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 诗词内容
|
||||
if (careController.selectedOptions.contains('诗词'))
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
try {
|
||||
await homeController.loadNextPoetry();
|
||||
} catch (e) {
|
||||
print('加载诗词失败: $e');
|
||||
}
|
||||
},
|
||||
child: _buildPoetryContent(
|
||||
poetryData,
|
||||
isDark,
|
||||
primaryColor,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 原文
|
||||
if (careController.selectedOptions.contains('原文'))
|
||||
_buildPoetryOriginal(poetryData, isDark, primaryColor),
|
||||
|
||||
if (careController.selectedOptions.contains('原文'))
|
||||
const SizedBox(height: 24),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 译文
|
||||
if (careController.selectedOptions.contains('译文'))
|
||||
_buildPoetryTranslation(poetryData, isDark, primaryColor),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 更多
|
||||
if (careController.selectedOptions.contains('更多'))
|
||||
_buildPoetryMore(poetryData, isDark, primaryColor),
|
||||
|
||||
const SizedBox(height: 48),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildPoetryTitle(
|
||||
dynamic poetryData,
|
||||
bool isDark,
|
||||
Color primaryColor,
|
||||
) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
poetryData.name ?? '未知标题',
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: primaryColor,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPoetryContent(
|
||||
dynamic poetryData,
|
||||
bool isDark,
|
||||
Color primaryColor,
|
||||
) {
|
||||
final themeController = Get.find<ThemeController>();
|
||||
final careController = Get.find<CareController>();
|
||||
final accentColor = themeController.currentAccentColor;
|
||||
final content = poetryData.name ?? '';
|
||||
final lines = content.split('\n');
|
||||
final showPinyin = careController.pinyinEnabled;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark
|
||||
? accentColor.withOpacity(0.2)
|
||||
: accentColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: lines.asMap().entries.map<Widget>((entry) {
|
||||
int index = entry.key;
|
||||
String line = entry.value;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Column(
|
||||
children: [
|
||||
if (showPinyin && line.trim().isNotEmpty)
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
children: PinyinHelper.convertToCharPinyinList(line)
|
||||
.asMap()
|
||||
.entries
|
||||
.map<Widget>((charEntry) {
|
||||
int charIndex = charEntry.key;
|
||||
var item = charEntry.value;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: AnimatedOpacity(
|
||||
opacity: 1.0,
|
||||
duration: Duration(
|
||||
milliseconds: 300 + charIndex * 100,
|
||||
),
|
||||
curve: Curves.easeOut,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
item['pinyin'] ?? '',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark
|
||||
? Colors.grey[400]
|
||||
: Colors.grey[600],
|
||||
height: 1.2,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Text(
|
||||
item['char'] ?? '',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
height: 1.6,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
),
|
||||
if (!showPinyin || line.trim().isEmpty)
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
children: line.split('').asMap().entries.map<Widget>((
|
||||
charEntry,
|
||||
) {
|
||||
int charIndex = charEntry.key;
|
||||
String char = charEntry.value;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: AnimatedOpacity(
|
||||
opacity: 1.0,
|
||||
duration: Duration(
|
||||
milliseconds: 300 + charIndex * 100,
|
||||
),
|
||||
curve: Curves.easeOut,
|
||||
child: Text(
|
||||
char,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
height: 1.6,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPoetrySource(
|
||||
dynamic poetryData,
|
||||
bool isDark,
|
||||
Color primaryColor,
|
||||
) {
|
||||
final url = poetryData.url ?? '未知作者';
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
url,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: primaryColor,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPoetryTranslation(
|
||||
dynamic poetryData,
|
||||
bool isDark,
|
||||
Color primaryColor,
|
||||
) {
|
||||
final translation = poetryData.introduce ?? '暂无译文';
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
translation,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: isDark ? Colors.grey[300] : Colors.grey[700],
|
||||
height: 1.6,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPoetryMore(dynamic poetryData, bool isDark, Color primaryColor) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'更多信息',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'诗词解析、背景知识等内容将在此显示',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: isDark ? Colors.grey[300] : Colors.grey[700],
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPoetryOriginal(
|
||||
dynamic poetryData,
|
||||
bool isDark,
|
||||
Color primaryColor,
|
||||
) {
|
||||
final original = poetryData.drtime ?? '暂无原文';
|
||||
final careController = Get.find<CareController>();
|
||||
final showPinyin = careController.pinyinEnabled;
|
||||
final lines = original.split('\n');
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: lines.asMap().entries.map<Widget>((entry) {
|
||||
int index = entry.key;
|
||||
String line = entry.value;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Column(
|
||||
children: [
|
||||
if (showPinyin && line.trim().isNotEmpty)
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
children: PinyinHelper.convertToCharPinyinList(line)
|
||||
.asMap()
|
||||
.entries
|
||||
.map<Widget>((charEntry) {
|
||||
int charIndex = charEntry.key;
|
||||
var item = charEntry.value;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: AnimatedOpacity(
|
||||
opacity: 1.0,
|
||||
duration: Duration(
|
||||
milliseconds: 300 + charIndex * 100,
|
||||
),
|
||||
curve: Curves.easeOut,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
item['pinyin'] ?? '',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark
|
||||
? Colors.grey[400]
|
||||
: Colors.grey[600],
|
||||
height: 1.2,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Text(
|
||||
item['char'] ?? '',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: primaryColor,
|
||||
height: 1.6,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
),
|
||||
if (!showPinyin || line.trim().isEmpty)
|
||||
Text(
|
||||
line,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: primaryColor,
|
||||
height: 1.6,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
171
lib/views/home/care/care_widgets.dart
Normal file
171
lib/views/home/care/care_widgets.dart
Normal file
@@ -0,0 +1,171 @@
|
||||
/// 时间: 2026-04-02
|
||||
/// 功能: 关怀模式相关组件
|
||||
/// 介绍: 包含关怀按钮和开关的UI组件
|
||||
/// 最新变化: 2026-04-02 初始创建
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../../services/get/theme_controller.dart';
|
||||
import '../../../services/get/care_controller.dart';
|
||||
import 'care-page.dart';
|
||||
|
||||
/// 关怀按钮组件
|
||||
class CareButton extends StatelessWidget {
|
||||
const CareButton({super.key, required this.onTap, required this.isDark});
|
||||
|
||||
final VoidCallback onTap;
|
||||
final bool isDark;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final themeController = Get.find<ThemeController>();
|
||||
final primaryColor = themeController.currentThemeColor;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(isDark ? 40 : 20),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(child: Icon(Icons.people, color: primaryColor, size: 24)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 关怀模式开关组件
|
||||
class CareModeToggle extends StatelessWidget {
|
||||
const CareModeToggle({
|
||||
super.key,
|
||||
required this.isEnabled,
|
||||
required this.onToggle,
|
||||
required this.isDark,
|
||||
});
|
||||
|
||||
final bool isEnabled;
|
||||
final VoidCallback onToggle;
|
||||
final bool isDark;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final themeController = Get.find<ThemeController>();
|
||||
final primaryColor = themeController.currentThemeColor;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
margin: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(isDark ? 40 : 20),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.people, color: primaryColor, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
GestureDetector(
|
||||
onTap: () => Get.to(() => const CarePage()),
|
||||
child: Text(
|
||||
'关怀',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: isDark ? Colors.white : Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Switch(
|
||||
value: isEnabled,
|
||||
onChanged: (_) => onToggle(),
|
||||
activeColor: primaryColor,
|
||||
inactiveTrackColor: isDark ? Colors.grey[700] : Colors.grey[300],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 关怀模式页面顶部开关组件
|
||||
class CarePageHeaderToggle extends StatelessWidget {
|
||||
const CarePageHeaderToggle({super.key, required this.isDark});
|
||||
|
||||
final bool isDark;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final themeController = Get.find<ThemeController>();
|
||||
final careController = Get.find<CareController>();
|
||||
final primaryColor = themeController.currentThemeColor;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
margin: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(isDark ? 40 : 20),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.people, color: primaryColor, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
GestureDetector(
|
||||
onTap: () => Get.to(() => const CarePage()),
|
||||
child: Text(
|
||||
'关怀模式',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: isDark ? Colors.white : Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Obx(
|
||||
() => Switch(
|
||||
value: careController.isCareModeEnabled,
|
||||
onChanged: (value) {
|
||||
// 关闭关怀模式并返回正常页面
|
||||
careController.toggleCareMode();
|
||||
},
|
||||
activeColor: primaryColor,
|
||||
inactiveTrackColor: isDark ? Colors.grey[700] : Colors.grey[300],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
79
lib/views/home/care/pinyin_helper.dart
Normal file
79
lib/views/home/care/pinyin_helper.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
/// 时间: 2026-04-02
|
||||
/// 功能: 拼音处理辅助类
|
||||
/// 介绍: 使用pinyin库为汉字生成带音调的拼音
|
||||
/// 最新变化: 2026-04-02 修正API使用方式,避免递归调用
|
||||
|
||||
import 'package:pinyin/pinyin.dart' as pinyin;
|
||||
|
||||
class PinyinHelper {
|
||||
/// 将汉字转换为带音调的拼音
|
||||
static String convertToPinyin(String text) {
|
||||
if (text.isEmpty) return '';
|
||||
|
||||
try {
|
||||
// 使用pinyin库将汉字转换为拼音
|
||||
return pinyin.PinyinHelper.getPinyin(
|
||||
text,
|
||||
separator: ' ',
|
||||
format: pinyin.PinyinFormat.WITH_TONE_MARK,
|
||||
);
|
||||
} catch (e) {
|
||||
// 无法转换时返回空字符串
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/// 为诗词内容生成拼音
|
||||
static String generatePoetryPinyin(String content) {
|
||||
if (content.isEmpty) return '';
|
||||
|
||||
// 按行分割诗词
|
||||
List<String> lines = content.split('\n');
|
||||
List<String> pinyinLines = [];
|
||||
|
||||
// 为每行生成拼音
|
||||
for (String line in lines) {
|
||||
if (line.trim().isNotEmpty) {
|
||||
String linePinyin = convertToPinyin(line);
|
||||
pinyinLines.add(linePinyin);
|
||||
} else {
|
||||
pinyinLines.add('');
|
||||
}
|
||||
}
|
||||
|
||||
return pinyinLines.join('\n');
|
||||
}
|
||||
|
||||
/// 将字符串转换为每个汉字及其对应的拼音的列表
|
||||
static List<Map<String, String>> convertToCharPinyinList(String text) {
|
||||
if (text.isEmpty) return [];
|
||||
|
||||
List<Map<String, String>> result = [];
|
||||
|
||||
try {
|
||||
// 为每个字符生成拼音
|
||||
for (int i = 0; i < text.length; i++) {
|
||||
String char = text[i];
|
||||
String charPinyin = '';
|
||||
|
||||
try {
|
||||
charPinyin = pinyin.PinyinHelper.getPinyin(
|
||||
char,
|
||||
separator: ' ',
|
||||
format: pinyin.PinyinFormat.WITH_TONE_MARK,
|
||||
);
|
||||
} catch (e) {
|
||||
// 无法转换时使用空字符串
|
||||
charPinyin = '';
|
||||
}
|
||||
|
||||
result.add({'char': char, 'pinyin': charPinyin});
|
||||
}
|
||||
} catch (e) {
|
||||
// 发生错误时返回空列表
|
||||
return [];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user