Flutter Video Player的initState()方法问题

时间:2020-05-02 23:45:53

标签: flutter flutter-layout flutter-dependencies

我的代码中initState()方法的位置似乎有问题。

   class WalkThrough extends StatefulWidget {
  @override
  _WalkThroughState createState() => _WalkThroughState();
}

class _WalkThroughState extends State<WalkThrough> {
  VideoPlayerController _controller;

没有这一行代码,当前将无法运行代码。

  noSuchMethod(Invocation i) => super.noSuchMethod(i);

  @override

以下initState()方法是否应该放在其他位置?

  void initState() {
    super.initState();
    // Pointing the video controller to our local asset.
    _controller = VideoPlayerController.asset("assets/coffee.mp4")
      ..initialize().then((_) {
        // Once the video has been loaded we play the video and set looping to true.
        _controller.play();
        _controller.setLooping(true);
        // Ensure the first frame is shown after the video is initialized.
        setState(() {});
      });

    Widget build(BuildContext context) {
      return Scaffold(
        body: Stack(
          children: <Widget>[
            SizedBox.expand(
              child: FittedBox(
                fit: BoxFit.fill,
                child: SizedBox(
                  width: _controller.value.size?.width ?? 0,
                  height: _controller.value.size?.height ?? 0,
                  child: VideoPlayer(_controller),
                ),
              ),
            ),

here is the error screen

0 个答案:

没有答案