mod: 未开启横屏时不转屏

This commit is contained in:
orz12
2024-02-14 00:23:20 +08:00
parent 9afa4758d3
commit fc834a7040
4 changed files with 79 additions and 46 deletions

View File

@@ -28,57 +28,65 @@ import './services/loggeer.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
MediaKit.ensureInitialized();
SystemChrome.setPreferredOrientations(
//支持竖屏与横屏
[
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
).then((_) async {
await GStrorage.init();
await setupServiceLocator();
Request();
await Request.setCookie();
RecommendFilter();
// 异常捕获 logo记录
final Catcher2Options debugConfig = Catcher2Options(
SilentReportMode(),
await GStrorage.init();
if (GStrorage.setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)) {
await SystemChrome.setPreferredOrientations(
//支持竖屏与横屏
[
FileHandler(await getLogsPath()),
ConsoleHandler(
enableDeviceParameters: false,
enableApplicationParameters: false,
)
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
);
final Catcher2Options releaseConfig = Catcher2Options(
SilentReportMode(),
[FileHandler(await getLogsPath())],
} else {
await SystemChrome.setPreferredOrientations(
//支持竖屏
[
DeviceOrientation.portraitUp,
],
);
}
await setupServiceLocator();
Request();
await Request.setCookie();
RecommendFilter();
Catcher2(
debugConfig: debugConfig,
releaseConfig: releaseConfig,
runAppFunction: () {
runApp(const MyApp());
},
);
// 异常捕获 logo记录
final Catcher2Options debugConfig = Catcher2Options(
SilentReportMode(),
[
FileHandler(await getLogsPath()),
ConsoleHandler(
enableDeviceParameters: false,
enableApplicationParameters: false,
)
],
);
// 小白条、导航栏沉浸
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.transparent,
systemNavigationBarDividerColor: Colors.transparent,
statusBarColor: Colors.transparent,
));
Data.init();
GStrorage.lazyInit();
PiliSchame.init();
});
final Catcher2Options releaseConfig = Catcher2Options(
SilentReportMode(),
[FileHandler(await getLogsPath())],
);
Catcher2(
debugConfig: debugConfig,
releaseConfig: releaseConfig,
runAppFunction: () {
runApp(const MyApp());
},
);
// 小白条、导航栏沉浸
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.transparent,
systemNavigationBarDividerColor: Colors.transparent,
statusBarColor: Colors.transparent,
));
Data.init();
GStrorage.lazyInit();
PiliSchame.init();
}
class MyApp extends StatelessWidget {

View File

@@ -1,6 +1,8 @@
import 'dart:io';
import 'package:auto_orientation/auto_orientation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/models/video/play/quality.dart';
@@ -116,11 +118,20 @@ class _PlaySettingState extends State<PlaySetting> {
setKey: SettingBoxKey.enableAutoExit,
defaultVal: false,
),
const SetSwitchItem(
SetSwitchItem(
title: '横屏适配(测试)',
subTitle: '开启该项在播放页启用横屏布局与逻辑',
setKey: SettingBoxKey.horizontalScreen,
defaultVal: false,
callFn: (value) {
if (value) {
autoScreen();
SmartDialog.showToast('已开启横屏适配');
} else {
AutoOrientation.portraitUpMode();
SmartDialog.showToast('已关闭横屏适配');
}
}
),
const SetSwitchItem(
title: '开启硬解',

View File

@@ -3,6 +3,7 @@ import 'dart:io';
import 'dart:math';
import 'dart:ui';
import 'package:auto_orientation/auto_orientation.dart';
import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';
import 'package:floating/floating.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
@@ -198,6 +199,9 @@ class _VideoDetailPageState extends State<VideoDetailPage>
@override
void dispose() {
if (!horizontalScreen) {
AutoOrientation.portraitUpMode();
}
shutdownTimerService.handleWaitingFinished();
if (plPlayerController != null) {
plPlayerController!.removeStatusLister(playerListener);

View File

@@ -42,6 +42,16 @@ Future<void> verticalScreen() async {
]);
}
//全向
Future<void> autoScreen() async {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
Future<void> enterFullScreen() async {
await SystemChrome.setEnabledSystemUIMode(
SystemUiMode.immersiveSticky,