我在其中一个选项卡中有一个带有列表视图的tabBarView。在列表视图中下方有手势检测器。我正在尝试展示一些newtwork视频。
VideoPlayerController playercontroller;
VideoPlayerController retcontroller(String varainatVideo){
if(playercontroller == null){
playercontroller = VideoPlayerController.network(varainatVideo);
}
return playercontroller;
}
GestureDetector(
child:AspectRatio(
aspectRatio: 16/9,
child:Stack(
children:<Widgets>[
Chewie(
retcontroller(stringVideo),
cupertinoProgressColors: ChewieProgressColors(),
showControls:false,
),
]
)
)
);
每当我从该选项卡栏切换到另一个并尝试导航到第二个tabBar的另一页时,我都会看到黑屏,而不是正常页面。但是当我删除videoPage时,我不会遇到此问题并在控制台
I/flutter (19985): Another exception was thrown: There are multiple heroes that share the same tag within a subtree.
I/flutter (19985): Another exception was thrown: There are multiple heroes that share the same tag within a subtree.
来自调试控制台的日志:
我试图弄清楚是什么,但是我似乎无法将与Hero Tag
关联的videoPlayerController
设置为null。
I/flutter (19985): ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (19985): The following assertion was thrown during a scheduler callback:
I/flutter (19985): There are multiple heroes that share the same tag within a subtree.
I/flutter (19985): Within each subtree for which heroes are to be animated (typically a PageRoute subtree), each Hero
I/flutter (19985): must have a unique non-null tag.
I/flutter (19985): In this case, multiple heroes had the following tag:
I/flutter (19985): VideoPlayerController#3144c(VideoPlayerValue(duration: null, size: null, position: 0:00:00.000000,
I/flutter (19985): buffered: [], isPlaying: false, isLooping: false, isBuffering: falsevolume: 1.0, errorDescription:
I/flutter (19985): null))
I/flutter (19985): Here is the subtree for one of the offending heroes:
I/flutter (19985): # Hero(tag: VideoPlayerController#3144c(VideoPlayerValue(duration: null, size: null, position: 0:00:00.000000, buffered: [], isPlaying: false, isLooping: false, isBuffering: falsevolume: 1.0, errorDescription: null)), state: _HeroState#b5c8f)
I/flutter (19985): # └KeyedSubtree-[GlobalKey#44acd]
I/flutter (19985): # └AspectRatio(aspectRatio: 1.7, renderObject: RenderAspectRatio#78caa relayoutBoundary=up2)
I/flutter (19985): # └VideoPlayer(state: _VideoPlayerState#62908)
I/flutter (19985): # └Container
I/flutter (19985): # └LimitedBox(maxWidth: 0.0, maxHeight: 0.0, renderObject: RenderLimitedBox#9e9b5)
I/flutter (19985): # └ConstrainedBox(BoxConstraints(biggest), renderObject: RenderConstrainedBox#1b4cb)
I/flutter (19985):
I/flutter (19985): When the exception was thrown, this was the stack:
I/flutter (19985): #0 Hero._allHeroesFor.visitor.<anonymous closure> (package:flutter/src/widgets/heroes.dart:191:13)
I/flutter (19985): #1 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:201:10)
I/flutter (19985): #2 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4784:14)
答案 0 :(得分:1)
您不应对多个VideoPlayerController
实例使用单例Chewie
,Chewie使用controller(第一个参数)作为英雄标签
答案 1 :(得分:1)
class Videos extends StatefulWidget {
@override
_VideoPlayerPageState createState() => _VideosState();
}
class _VideosState extends State<Videos> {
List<String> videoList;
@override
Widget build(BuildContext context) {
// TODO: implement build
final videoList = _dir
.listSync()
.map((item) => item.path)
.where((item) =>
item.endsWith(".mp4") ||
item.endsWith(".avi") ||
item.endsWith(".webm"))
.toList(growable: false);
if (videoList != null) {
if (videoList.length > 0) {
return ListView.builder(
padding: EdgeInsets.only(left: 10, right: 10, bottom: 16),
itemBuilder: (BuildContext _context, int index) {
if (index >= videoList.length) {
return null;
}
return VideoPlayerScreen(
path: videoList[index],
);
});
}
}
return VideoPlayerScreen(
path: videoList[0],
);
}
}