pikapika/lib/basic/config/AndroidSecureFlag.dart

62 lines
1.6 KiB
Dart
Raw Normal View History

2021-10-29 03:38:36 +00:00
/// 音量键翻页
import 'dart:io';
import 'package:flutter/material.dart';
import '../Common.dart';
import '../Method.dart';
2022-07-09 07:11:26 +00:00
import 'IsPro.dart';
2021-10-29 03:38:36 +00:00
2021-11-04 05:56:25 +00:00
const _propertyName = "androidSecureFlag";
2021-10-29 03:38:36 +00:00
2021-11-04 05:56:25 +00:00
late bool _androidSecureFlag;
2021-10-29 03:38:36 +00:00
Future<void> initAndroidSecureFlag() async {
if (Platform.isAndroid) {
2021-11-04 05:56:25 +00:00
_androidSecureFlag =
(await method.loadProperty(_propertyName, "false")) == "true";
if (_androidSecureFlag) {
2021-10-29 03:38:36 +00:00
await method.androidSecureFlag(true);
}
}
}
2021-11-04 05:56:25 +00:00
Future<void> _chooseAndroidSecureFlag(BuildContext context) async {
2021-10-29 03:38:36 +00:00
String? result =
await chooseListDialog<String>(context, "禁止截图/禁止显示在任务视图", ["", ""]);
if (result != null) {
var target = result == "";
2021-11-04 05:56:25 +00:00
await method.saveProperty(_propertyName, "$target");
_androidSecureFlag = target;
await method.androidSecureFlag(_androidSecureFlag);
2021-10-29 03:38:36 +00:00
}
}
Widget androidSecureFlagSetting() {
if (Platform.isAndroid) {
return StatefulBuilder(builder:
(BuildContext context, void Function(void Function()) setState) {
return ListTile(
2022-07-09 07:11:26 +00:00
title: Text(
"禁止截图/禁止显示在任务视图" + (!isPro ? "(发电)" : ""),
style: TextStyle(
color: !isPro ? Colors.grey : null,
),
),
subtitle: Text(
_androidSecureFlag ? "" : "",
),
2021-10-29 03:38:36 +00:00
onTap: () async {
2022-07-09 07:11:26 +00:00
if (!isPro) {
defaultToast(context, "请先发电再使用");
return;
}
2021-11-04 05:56:25 +00:00
await _chooseAndroidSecureFlag(context);
2021-10-29 03:38:36 +00:00
setState(() {});
});
});
}
return Container();
}