web端修复

This commit is contained in:
Developer
2026-04-01 01:34:22 +08:00
parent ab9961853d
commit 6517a78c7e
12 changed files with 2390 additions and 46 deletions

View File

@@ -9,11 +9,12 @@ import 'dart:io' as io;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import '../../constants/app_constants.dart';
import '../../controllers/history_controller.dart';
import '../../controllers/shared_preferences_storage_controller.dart';
import '../../services/wakelock_service.dart';
import 'history_page.dart';
import 'per_card.dart';
import 'settings/app_fun.dart';
@@ -802,6 +803,11 @@ class _ProfilePageState extends State<ProfilePage>
}
Widget _buildScreenWakeItem() {
// Web 平台不支持屏幕常亮功能,不显示该项
if (kIsWeb) {
return const SizedBox.shrink();
}
// === 屏幕常亮设置项:显示图标、标题和开关 ===
return ListTile(
leading: Icon(
@@ -912,6 +918,16 @@ class _ProfilePageState extends State<ProfilePage>
}
Future<void> _toggleScreenWake(bool enable) async {
// Web 平台不支持 wakelock_plus
if (kIsWeb) {
if (mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Web 平台不支持屏幕常亮功能')));
}
return;
}
try {
// 使用 io.Platform 检测平台
final String osName = io.Platform.operatingSystem;
@@ -919,14 +935,14 @@ class _ProfilePageState extends State<ProfilePage>
print('Current platform: $osName, version: $osVersion');
if (enable) {
await WakelockPlus.enable();
await WakelockService.instance.enable();
if (mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('屏幕常亮已开启')));
}
} else {
await WakelockPlus.disable();
await WakelockService.instance.disable();
if (mounted) {
ScaffoldMessenger.of(
context,
@@ -938,7 +954,7 @@ class _ProfilePageState extends State<ProfilePage>
_isScreenWakeEnabled = enable;
});
} catch (e, stackTrace) {
print('WakelockPlus error: $e');
print('WakelockService error: $e');
print('Stack trace: $stackTrace');
if (mounted) {
// 检查错误类型,判断是否是设备不支持