pikapika/lib/basic/config/FullScreenUI.dart

117 lines
2.8 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
/// 全屏操作
2021-12-07 15:53:19 +00:00
import 'dart:io';
2021-09-29 23:57:09 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../Common.dart';
import '../Method.dart';
enum FullScreenUI {
NO,
HIDDEN_BOTTOM,
ALL,
}
2021-11-04 05:56:25 +00:00
const _propertyName = "fullScreenUI";
2021-09-29 23:57:09 +00:00
late FullScreenUI fullScreenUI;
Future<void> initFullScreenUI() async {
fullScreenUI = _fullScreenUIFromString(await method.loadProperty(
_propertyName,
FullScreenUI.NO.toString(),
));
2023-03-23 09:44:42 +00:00
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
systemStatusBarContrastEnforced: true,
systemNavigationBarContrastEnforced: true,
));
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.edgeToEdge,
overlays: SystemUiOverlay.values,
);
switchFullScreenUI();
2021-09-29 23:57:09 +00:00
}
FullScreenUI _fullScreenUIFromString(String string) {
for (var value in FullScreenUI.values) {
if (string == value.toString()) {
return value;
}
}
return FullScreenUI.NO;
}
Map<String, FullScreenUI> fullScreenUIMap = {
"不使用": FullScreenUI.NO,
"去除虚拟控制器": FullScreenUI.HIDDEN_BOTTOM,
"全屏": FullScreenUI.ALL,
};
String currentFullScreenUIName() {
for (var e in fullScreenUIMap.entries) {
if (e.value == fullScreenUI) {
return e.key;
}
}
return '';
}
Future<void> chooseFullScreenUI(BuildContext context) async {
2021-11-04 03:45:22 +00:00
FullScreenUI? result =
await chooseMapDialog<FullScreenUI>(context, fullScreenUIMap, "选择全屏UI");
2021-09-29 23:57:09 +00:00
if (result != null) {
await method.saveProperty(_propertyName, result.toString());
fullScreenUI = result;
switchFullScreenUI();
}
}
void switchFullScreenUI() {
List<SystemUiOverlay> list = [...SystemUiOverlay.values];
switch (fullScreenUI) {
case FullScreenUI.HIDDEN_BOTTOM:
2023-03-23 09:44:42 +00:00
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: [SystemUiOverlay.top],
);
2021-09-29 23:57:09 +00:00
break;
case FullScreenUI.ALL:
2023-03-23 09:44:42 +00:00
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: [],
);
2021-09-29 23:57:09 +00:00
break;
2022-03-17 03:31:25 +00:00
case FullScreenUI.NO:
2023-03-23 09:44:42 +00:00
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.edgeToEdge,
overlays: SystemUiOverlay.values,
);
2022-03-17 03:31:25 +00:00
break;
2021-09-29 23:57:09 +00:00
}
2021-12-07 15:53:19 +00:00
if (Platform.isAndroid || Platform.isIOS) {
SystemChrome.setEnabledSystemUIMode(
2023-03-23 09:44:42 +00:00
SystemUiMode.edgeToEdge,
overlays: list,
);
2021-12-07 15:53:19 +00:00
}
2021-09-29 23:57:09 +00:00
}
2021-11-04 03:45:22 +00:00
Widget fullScreenUISetting() {
2021-12-07 15:53:19 +00:00
if (Platform.isAndroid || Platform.isIOS) {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return ListTile(
2022-03-17 03:31:25 +00:00
title: const Text("全屏UI"),
2021-12-07 15:53:19 +00:00
subtitle: Text(currentFullScreenUIName()),
onTap: () async {
await chooseFullScreenUI(context);
setState(() {});
},
);
},
);
}
return Container();
2021-11-04 03:45:22 +00:00
}