pikapika/lib/basic/config/FullScreenAction.dart

76 lines
1.9 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
/// 全屏操作
import 'package:flutter/material.dart';
import '../Common.dart';
import '../Method.dart';
enum FullScreenAction {
CONTROLLER,
TOUCH_ONCE,
2021-11-29 03:26:30 +00:00
THREE_AREA,
2021-09-29 23:57:09 +00:00
}
2021-11-04 05:56:25 +00:00
Map<String, FullScreenAction> _fullScreenActionMap = {
"点击屏幕一次全屏": FullScreenAction.TOUCH_ONCE,
"使用控制器全屏": FullScreenAction.CONTROLLER,
"将屏幕划分成三个区域 (上一页, 下一页, 全屏)": FullScreenAction.THREE_AREA,
2021-11-04 05:56:25 +00:00
};
2021-09-29 23:57:09 +00:00
const _defaultController = FullScreenAction.TOUCH_ONCE;
2021-09-29 23:57:09 +00:00
const _propertyName = "fullScreenAction";
2021-11-04 05:56:25 +00:00
late FullScreenAction _fullScreenAction;
2021-09-29 23:57:09 +00:00
Future<void> initFullScreenAction() async {
2021-11-04 05:56:25 +00:00
_fullScreenAction = _fullScreenActionFromString(await method.loadProperty(
2021-09-29 23:57:09 +00:00
_propertyName,
FullScreenAction.CONTROLLER.toString(),
));
}
2021-11-04 05:56:25 +00:00
FullScreenAction currentFullScreenAction() {
return _fullScreenAction;
}
2021-09-29 23:57:09 +00:00
FullScreenAction _fullScreenActionFromString(String string) {
for (var value in FullScreenAction.values) {
if (string == value.toString()) {
return value;
}
}
return _defaultController;
2021-09-29 23:57:09 +00:00
}
2021-12-03 10:51:21 +00:00
String currentFullScreenActionName() {
2021-11-04 05:56:25 +00:00
for (var e in _fullScreenActionMap.entries) {
if (e.value == _fullScreenAction) {
2021-09-29 23:57:09 +00:00
return e.key;
}
}
return '';
}
2021-12-03 10:51:21 +00:00
Future<void> chooseFullScreenAction(BuildContext context) async {
2021-09-29 23:57:09 +00:00
FullScreenAction? result = await chooseMapDialog<FullScreenAction>(
context, _fullScreenActionMap, "选择操控方式");
2021-09-29 23:57:09 +00:00
if (result != null) {
await method.saveProperty(_propertyName, result.toString());
2021-11-04 05:56:25 +00:00
_fullScreenAction = result;
2021-09-29 23:57:09 +00:00
}
}
2021-11-04 03:45:22 +00:00
Widget fullScreenActionSetting() {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return ListTile(
title: Text("操控方式"),
2021-12-03 10:51:21 +00:00
subtitle: Text(currentFullScreenActionName()),
2021-11-04 03:45:22 +00:00
onTap: () async {
2021-12-03 10:51:21 +00:00
await chooseFullScreenAction(context);
2021-11-04 03:45:22 +00:00
setState(() {});
},
);
},
);
}