【发布时间】:2020-08-18 00:13:37
【问题描述】:
我正在尝试为我的应用创建背景视频闪屏。 目前,我通过运行此代码实现了一个空白屏幕。
void main() => runApp(WalkThrough());
class WalkThrough extends StatefulWidget {
@override
_WalkThroughState createState() => _WalkThroughState();
}
class _WalkThroughState extends State<WalkThrough> {
VideoPlayerController _controller;
@override
void initState() {
super.initState();
// Pointing the video controller to our local asset.
_controller = VideoPlayerController.asset('assets/video.mp4')
..initialize().then((_) {
// Once the video has been loaded we play the video and set looping to true.
_controller.play();
_controller.setLooping(true);
_controller.setVolume(0.0);
_controller.play();
// Ensure the first frame is shown after the video is initialized.
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
我怀疑问题可能出在此处,并且我的研究基于此Full screen video background in Flutter on Login,因为我正试图获得类似的结果。
SizedBox.expand(
child: FittedBox(
// If your background video doesn't look right, try changing the BoxFit property.
// BoxFit.fill created the look I was going for.
fit: BoxFit.fill,
child: SizedBox(
width: _controller.value.size?.width ?? 0,
height: _controller.value.size?.height ?? 0,
child: VideoPlayer(_controller),
),
),
),
【问题讨论】:
-
你的设备是什么?
-
@PayamZahedi iPhone 11 Pro
-
是真机还是模拟器?
-
您也没有使用 MaterialApp 小部件。你用它包裹脚手架后试过吗?
-
@PayamZahedi 模拟器
标签: flutter flutter-layout flutter-dependencies