发生异常。状态不佳:Flutter 列表视图和视频播放器中的未来已经完成

Nor*_*ert 3 dart flutter

我从我的 CloudFirestore 数据库中获取了一个视频 URL,并在 listView.buiilder() 中显示了网络视频。 在此处输入图片说明 当我设置

autiInitialize = true
Run Code Online (Sandbox Code Playgroud)

或尝试以任何其他方式初始化视频我收到错误

Exception has occurred.
Bad state: Future already completed
Run Code Online (Sandbox Code Playgroud)

I/flutter ( 6187): ??? EXCEPTION CAUGHT BY FOUNDATION LIBRARY ?????????????????????????????????????????????????????????
I/flutter ( 6187): The following assertion was thrown while dispatching notifications for VideoPlayerController: 
I/flutter ( 6187): setState() or markNeedsBuild() called during build.
I/flutter ( 6187): This MaterialControls widget cannot be marked as needing to build because the framework is already
I/flutter ( 6187): in the process of building widgets. A widget can be marked as needing to be built during the build
I/flutter ( 6187): phase only if one of its ancestors is currently building. This exception is allowed because the
I/flutter ( 6187): framework builds parent widgets before children, which means a dirty descendant will always be
I/flutter ( 6187): built. Otherwise, the framework might not visit this widget during this build phase.
I/flutter ( 6187): The widget on which setState() or markNeedsBuild() was called was:
I/flutter ( 6187):   MaterialControls(state: _MaterialControlsState#47383)
Run Code Online (Sandbox Code Playgroud)

我的代码的一部分

VideoPlayerController  retcontroller(String varainatVideo){
    if(playercontroller == null){
      playercontroller = VideoPlayerController.network(varainatVideo);
    }
    return playercontroller;
  }


   Chewie(
  retcontroller(${snapshotDocuments[index].data['videos']}),
 autoInitialize: true,
cupertinoProgressColors: ChewieProgressColors(),
showControls:false,
 ),
Run Code Online (Sandbox Code Playgroud)

小智 8

像你看上去正试图在UI构建过程中更改状态,确保你没有使用setState(...)ListView.builder(...)

这个作为例子。