我已经创建了一个函数,它可以在全屏模式下播放视频。
import 'package:flutter/services.dart';
.
.
void pushFullScreenVideo() {
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
SystemChrome.setEnabledSystemUIOverlays([]);
SystemChrome.setPreferredOrientations(
[
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
);
Navigator.of(navigatorKey.currentContext)
.push(
PageRouteBuilder(
opaque: false,
settings: RouteSettings(),
pageBuilder: (
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
) {
return Scaffold(
backgroundColor: Colors.transparent,
resizeToAvoidBottomPadding: false,
body: Dismissible(
key: const Key('key'),
direction: DismissDirection.vertical,
onDismissed: (_) => Navigator.of(context).pop(),
child: OrientationBuilder(
builder: (context, orientation) {
isPortrait = orientation == Orientation.portrait;
return Center(
child: Stack(
fit: isPortrait ? StackFit.loose : StackFit.expand,
children: [
AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: VideoPlayer(controller),
),
],
),
);
},
);
},
),
)
.then(
(value) {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
SystemChrome.setPreferredOrientations(
[
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
],
);
},
);
}