屏幕常亮
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import '../../../constants/app_constants.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
|
||||
class PopMenu extends StatelessWidget {
|
||||
final VoidCallback? onRefresh;
|
||||
@@ -41,6 +42,46 @@ class PopMenu extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> toggleScreenWake(BuildContext context) async {
|
||||
try {
|
||||
// 检查当前状态
|
||||
final bool isEnabled = await WakelockPlus.enabled;
|
||||
|
||||
// 切换状态
|
||||
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) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('提示'),
|
||||
content: const Text('该设备不支持屏幕常亮功能'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void show(
|
||||
BuildContext context, {
|
||||
VoidCallback? onRefresh,
|
||||
@@ -89,9 +130,9 @@ class PopMenu extends StatelessWidget {
|
||||
}),
|
||||
_buildBottomSheetItem(
|
||||
context,
|
||||
'扫描二维码',
|
||||
Icons.qr_code_scanner,
|
||||
onScanQr,
|
||||
'屏幕常亮',
|
||||
Icons.screen_lock_rotation,
|
||||
() => toggleScreenWake(context),
|
||||
),
|
||||
_buildBottomSheetItem(context, '夜间模式', Icons.dark_mode, onDarkMode),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
Reference in New Issue
Block a user