发生异常。不良状态:Future 已经在颤振列表视图和视频播放器中完成

Posted

技术标签:

【中文标题】发生异常。不良状态:Future 已经在颤振列表视图和视频播放器中完成【英文标题】:Exception has occurred. Bad state: Future already completed in flutter listview and Video player 【发布时间】:2019-01-31 08:22:21 【问题描述】:

我从我的 CloudFirestore 数据库中获取了一个视频 url,并在 listView.buiilder() 中显示了网络视频。 当我设置

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】:

看起来您正在尝试在 UI 构建期间更改状态,请确保您没有在 ListView.builder(...) 中使用 setState(...)

以this为例。

【讨论】:

以上是关于发生异常。不良状态:Future 已经在颤振列表视图和视频播放器中完成的主要内容,如果未能解决你的问题,请参考以下文章

颤振类型错误future <dynamic> 不是future <bool> 类型的子类型

在颤振列表中使用未来对象的数据

颤振列表值未更新

列表项的颤振状态更新

在颤振飞镖中将 Future<int> 转换为 int

在颤振中调试时出现异常错误