web端修复
This commit is contained in:
0
lib/views/profile/components/entire -page.dart
Normal file
0
lib/views/profile/components/entire -page.dart
Normal file
@@ -1,8 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import '../../../constants/app_constants.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
import '../../../services/wakelock_service.dart';
|
||||
import 'dart:io' as io;
|
||||
|
||||
class PopMenu extends StatelessWidget {
|
||||
@@ -44,6 +45,16 @@ class PopMenu extends StatelessWidget {
|
||||
}
|
||||
|
||||
static Future<void> toggleScreenWake(BuildContext context) async {
|
||||
// Web 平台不支持 wakelock_plus
|
||||
if (kIsWeb) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('Web 平台不支持屏幕常亮功能')));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用 io.Platform 检测平台
|
||||
final String osName = io.Platform.operatingSystem;
|
||||
@@ -51,7 +62,7 @@ class PopMenu extends StatelessWidget {
|
||||
print('Current platform: $osName, version: $osVersion');
|
||||
|
||||
// 直接尝试启用屏幕常亮
|
||||
await WakelockPlus.enable();
|
||||
await WakelockService.instance.enable();
|
||||
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
@@ -59,7 +70,7 @@ class PopMenu extends StatelessWidget {
|
||||
).showSnackBar(const SnackBar(content: Text('屏幕常亮已开启')));
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
print('WakelockPlus error: $e');
|
||||
print('WakelockService error: $e');
|
||||
print('Stack trace: $stackTrace');
|
||||
if (context.mounted) {
|
||||
// 检查错误类型,判断是否是设备不支持
|
||||
|
||||
Reference in New Issue
Block a user