71 lines
1.9 KiB
Dart
71 lines
1.9 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
//横屏
|
|
Future<void> landScape() async {
|
|
dynamic document;
|
|
try {
|
|
if (kIsWeb) {
|
|
await document.documentElement?.requestFullscreen();
|
|
} else if (Platform.isAndroid || Platform.isIOS) {
|
|
await SystemChrome.setEnabledSystemUIMode(
|
|
SystemUiMode.immersiveSticky,
|
|
overlays: [],
|
|
);
|
|
await SystemChrome.setPreferredOrientations(
|
|
[
|
|
DeviceOrientation.landscapeLeft,
|
|
DeviceOrientation.landscapeRight,
|
|
],
|
|
);
|
|
} else if (Platform.isMacOS || Platform.isWindows || Platform.isLinux) {
|
|
await const MethodChannel('com.alexmercerind/media_kit_video')
|
|
.invokeMethod(
|
|
'Utils.EnterNativeFullscreen',
|
|
);
|
|
}
|
|
} catch (exception, stacktrace) {
|
|
debugPrint(exception.toString());
|
|
debugPrint(stacktrace.toString());
|
|
}
|
|
}
|
|
|
|
//竖屏
|
|
Future<void> verticalScreen() async {
|
|
await SystemChrome.setPreferredOrientations([
|
|
DeviceOrientation.portraitUp,
|
|
]);
|
|
}
|
|
|
|
Future<void> enterFullScreen() async {
|
|
await SystemChrome.setEnabledSystemUIMode(
|
|
SystemUiMode.immersiveSticky,
|
|
);
|
|
}
|
|
|
|
//退出全屏显示
|
|
Future<void> exitFullScreen() async {
|
|
dynamic document;
|
|
try {
|
|
if (kIsWeb) {
|
|
document.exitFullscreen();
|
|
} else if (Platform.isAndroid || Platform.isIOS) {
|
|
await SystemChrome.setEnabledSystemUIMode(
|
|
SystemUiMode.manual,
|
|
overlays: SystemUiOverlay.values,
|
|
);
|
|
await SystemChrome.setPreferredOrientations([]);
|
|
} else if (Platform.isMacOS || Platform.isWindows || Platform.isLinux) {
|
|
await const MethodChannel('com.alexmercerind/media_kit_video')
|
|
.invokeMethod(
|
|
'Utils.ExitNativeFullscreen',
|
|
);
|
|
}
|
|
} catch (exception, stacktrace) {
|
|
debugPrint(exception.toString());
|
|
debugPrint(stacktrace.toString());
|
|
}
|
|
}
|