Skip to content

Commit

Permalink
mod: 未开启横屏时不转屏
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Feb 13, 2024
1 parent 9afa475 commit fc834a7
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 46 deletions.
98 changes: 53 additions & 45 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
],
);

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();
});
// 小白条、导航栏沉浸
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 {
Expand Down
13 changes: 12 additions & 1 deletion lib/pages/setting/play_setting.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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: '开启硬解',
Expand Down
4 changes: 4 additions & 0 deletions lib/pages/video/detail/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -198,6 +199,9 @@ class _VideoDetailPageState extends State<VideoDetailPage>

@override
void dispose() {
if (!horizontalScreen) {
AutoOrientation.portraitUpMode();
}
shutdownTimerService.handleWaitingFinished();
if (plPlayerController != null) {
plPlayerController!.removeStatusLister(playerListener);
Expand Down
10 changes: 10 additions & 0 deletions lib/plugin/pl_player/utils/fullscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fc834a7

Please sign in to comment.