release
This commit is contained in:
@@ -5,9 +5,11 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:math' show Random;
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
|
||||
import '../../constants/app_constants.dart';
|
||||
import '../../controllers/history_controller.dart';
|
||||
@@ -44,6 +46,7 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
int _currentPage = 1; // 默认显示第2页(设置)
|
||||
bool _isCardExpanded = false; // 个人卡片展开状态
|
||||
bool _isStatsHidden = false; // 统计数据隐藏状态
|
||||
bool _isScreenWakeEnabled = false; // 屏幕常亮状态
|
||||
double _startY = 0.0;
|
||||
// 历史记录相关
|
||||
List<Map<String, dynamic>> _poetryHistory = [];
|
||||
@@ -409,7 +412,7 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
if (!_isStatsHidden) ...[
|
||||
_buildInfoItem('今日浏览', '$_todayViews 条'),
|
||||
_buildInfoItem('本周浏览', '$_weekViews 条'),
|
||||
_buildInfoItem('天数', '$_useDays 天'),
|
||||
_buildInfoItem('已用', '$_useDays 天'),
|
||||
_buildInfoItem('数据', _dataSize),
|
||||
_buildInfoItem('笔记', '$_noteCount 个'),
|
||||
_buildInfoItem('今日答题', '$_todayQuestions 题'),
|
||||
@@ -521,6 +524,12 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
children: [
|
||||
// === 账户设置组 ===
|
||||
_buildSettingsGroup('软件设置', [
|
||||
_buildSettingsItem(
|
||||
'功能设置',
|
||||
Icons.verified_user,
|
||||
() => _navigateToAppFunSettings(),
|
||||
),
|
||||
|
||||
_buildSettingsItem(
|
||||
'离线使用',
|
||||
Icons.volunteer_activism,
|
||||
@@ -531,11 +540,7 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
Icons.history,
|
||||
() => _navigateToHistoryPage(),
|
||||
),
|
||||
_buildSettingsItem(
|
||||
'功能设置',
|
||||
Icons.verified_user,
|
||||
() => _navigateToAppFunSettings(),
|
||||
),
|
||||
|
||||
_buildSettingsItem(
|
||||
'主题风格',
|
||||
Icons.palette,
|
||||
@@ -580,11 +585,7 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
Icons.cleaning_services,
|
||||
() => showBugListBottomSheet(context),
|
||||
),
|
||||
_buildSettingsItem(
|
||||
'关闭退出',
|
||||
Icons.palette,
|
||||
() => _showSnackBar('重启 关闭?'),
|
||||
),
|
||||
_buildScreenWakeItem(),
|
||||
]),
|
||||
],
|
||||
);
|
||||
@@ -800,6 +801,173 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildScreenWakeItem() {
|
||||
// === 屏幕常亮设置项:显示图标、标题和开关 ===
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
Icons.screen_lock_rotation,
|
||||
color: AppConstants.primaryColor,
|
||||
size: 20,
|
||||
),
|
||||
title: Text(
|
||||
'屏幕常亮',
|
||||
style: const TextStyle(fontSize: 14, color: Colors.black87),
|
||||
),
|
||||
trailing: Switch(
|
||||
value: _isScreenWakeEnabled,
|
||||
onChanged: (value) async {
|
||||
if (value) {
|
||||
// 显示提示对话框
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
color: AppConstants.primaryColor,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
'屏幕常亮提示',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'⚠️ 注意事项',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.orange[600],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'• OLED屏幕长时间显示相同内容可能会造成不可逆老化',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'• 开启常亮后,配合自动刷新内容的设置,实现常亮自动加载诗句',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'• 挂起常亮后,需保持该软件在屏幕中显示,记得关闭常亮哦!',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: Colors.grey[600],
|
||||
),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
await _toggleScreenWake(true);
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppConstants.primaryColor,
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
await _toggleScreenWake(false);
|
||||
}
|
||||
},
|
||||
activeColor: AppConstants.primaryColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _toggleScreenWake(bool enable) async {
|
||||
try {
|
||||
// 使用 io.Platform 检测平台
|
||||
final String osName = io.Platform.operatingSystem;
|
||||
final String osVersion = io.Platform.operatingSystemVersion;
|
||||
print('Current platform: $osName, version: $osVersion');
|
||||
|
||||
if (enable) {
|
||||
await WakelockPlus.enable();
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('屏幕常亮已开启')));
|
||||
}
|
||||
} else {
|
||||
await WakelockPlus.disable();
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('屏幕常亮已关闭')));
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isScreenWakeEnabled = enable;
|
||||
});
|
||||
} catch (e, stackTrace) {
|
||||
print('WakelockPlus error: $e');
|
||||
print('Stack trace: $stackTrace');
|
||||
if (mounted) {
|
||||
// 检查错误类型,判断是否是设备不支持
|
||||
String errorMessage;
|
||||
if (e.toString().contains('not supported') ||
|
||||
e.toString().contains('unsupported') ||
|
||||
e.toString().contains('不支持')) {
|
||||
errorMessage = '该设备不支持屏幕常亮功能';
|
||||
} else {
|
||||
errorMessage = '屏幕常亮功能异常: $e';
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('提示'),
|
||||
content: Text(errorMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildInteractionItem(String label, String value) {
|
||||
// === 互动统计项:显示标签和数值 ===
|
||||
return Expanded(
|
||||
|
||||
Reference in New Issue
Block a user