release
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import '../../../constants/app_constants.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
import 'dart:io' as io;
|
||||
|
||||
class PopMenu extends StatelessWidget {
|
||||
final VoidCallback? onRefresh;
|
||||
@@ -44,32 +45,38 @@ class PopMenu extends StatelessWidget {
|
||||
|
||||
static Future<void> toggleScreenWake(BuildContext context) async {
|
||||
try {
|
||||
// 检查当前状态
|
||||
final bool isEnabled = await WakelockPlus.enabled;
|
||||
// 使用 io.Platform 检测平台
|
||||
final String osName = io.Platform.operatingSystem;
|
||||
final String osVersion = io.Platform.operatingSystemVersion;
|
||||
print('Current platform: $osName, version: $osVersion');
|
||||
|
||||
// 直接尝试启用屏幕常亮
|
||||
await WakelockPlus.enable();
|
||||
|
||||
// 切换状态
|
||||
if (isEnabled) {
|
||||
await WakelockPlus.disable();
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('屏幕常亮已关闭')));
|
||||
}
|
||||
} else {
|
||||
await WakelockPlus.enable();
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('屏幕常亮已开启')));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('屏幕常亮已开启')));
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
print('WakelockPlus error: $e');
|
||||
print('Stack trace: $stackTrace');
|
||||
if (context.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: const Text('该设备不支持屏幕常亮功能'),
|
||||
content: Text(errorMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
@@ -134,9 +141,11 @@ class PopMenu extends StatelessWidget {
|
||||
Icons.screen_lock_rotation,
|
||||
() => toggleScreenWake(context),
|
||||
),
|
||||
_buildBottomSheetItem(context, '夜间模式', Icons.dark_mode, onDarkMode),
|
||||
_buildBottomSheetItem(context, '取消', Icons.settings, onSettings),
|
||||
const SizedBox(height: 20),
|
||||
_buildBottomSheetItem(context, '设置', Icons.settings, onSettings),
|
||||
_buildBottomSheetItem(context, '返回桌面', Icons.exit_to_app, () {
|
||||
SystemNavigator.pop();
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user