我想在Landing2类中显示它,但运行后会显示白屏。
这是我的代码:
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
class Landing2 extends StatefulWidget {
Landing2() : super();
@override
Landing2State createState() => Landing2State();
}
class Landing2State extends State<Landing2> {
VideoPlayerController _controller;
Future<void> _initializeVideoPlayerFuture;
@override
void initState() {
_controller = VideoPlayerController.asset("videos/video.mp4");
print(_controller);
_initializeVideoPlayerFuture = _controller.initialize();
_controller.setLooping(true);
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder(
future: _initializeVideoPlayerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller));
} else {
return Center(child: CircularProgressIndicator());
}
}));
}
}