有可能一直在播放背景视频吗?
我一直在寻找一些软件包并试图使其运行,但我不知道如何。
也许在视频中使用类似的东西。
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("images/f1.jpg"),
fit: BoxFit.cover,
),),
在容器内。
答案 0 :(得分:6)
使用FittedBox小部件处理溢出的解决方案:
Stack(
children: <Widget>[
SizedBox.expand(
child: FittedBox(
fit: BoxFit.cover,
child: SizedBox(
width: _controller.value.size?.width ?? 0,
height: _controller.value.size?.height ?? 0,
child: VideoPlayer(_controller),
),
),
),
LoginWidget()
],
)
一个完整的例子是:
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
void main() => runApp(BackgroundVideo());
class BackgroundVideo extends StatefulWidget {
@override
_BackgroundVideoState createState() => _BackgroundVideoState();
}
class _BackgroundVideoState extends State<BackgroundVideo> {
VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'http://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4')
..initialize().then((_) {
_controller.play();
_controller.setLooping(true);
// Ensure the first frame is shown after the video is initialized
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
children: <Widget>[
SizedBox.expand(
child: FittedBox(
fit: BoxFit.cover,
child: SizedBox(
width: _controller.value.size?.width ?? 0,
height: _controller.value.size?.height ?? 0,
child: VideoPlayer(_controller),
),
),
),
LoginWidget()
],
),
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
class LoginWidget extends StatelessWidget {
const LoginWidget({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(),
Container(
padding: EdgeInsets.all(16),
width: 300,
height: 200,
color: Colors.grey.withAlpha(200),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
TextField(
decoration: InputDecoration(
hintText: 'Username',
),
),
TextField(
decoration: InputDecoration(
hintText: 'Password',
),
),
RaisedButton(
child: Text('Login'),
onPressed: () {},
),
],
),
),
],
);
}
}
答案 1 :(得分:2)
尝试使用此软件包https://pub.dartlang.org/packages/video_player,下面提供的示例非常简单。然后,您可以将视频窗口小部件放置在Stack布局内,并在其中叠加显示的内容-https://docs.flutter.io/flutter/widgets/Stack-class.html您可以通过github链接向创建者发送电子邮件的任何功能请求