发生异常。糟糕的状态:未来已经在波动的列表视图和视频播放器中完成

时间:2018-08-24 20:45:20

标签: dart flutter

我正在获取从CloudFirestore数据库存储的视频URL,并在listView.buiilder()中显示网络视频。 enter image description here 当我设置

autiInitialize = true

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

Exception has occurred.
Bad state: Future already completed

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)

我的部分代码

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,
 ),

1 个答案:

答案 0 :(得分:1)

好像您正在尝试在UI构建过程中更改状态,请确保您未在​​interval()中使用setState(...)

this为例。