本文主要是介绍flutter: Another exception was thrown: Multiple widgets used the same GlobalKey,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
该问题原因多个widget重复使用同一GlobalKey导致的,
我的代码如下:
// 初始化一个 GlobalKey 传递 key 从SliverCollapsingWidget 到 NftBlurImageWidget
传递过程中两个weidget同时使用了videoKey
final GlobalKey<VideoWidgetState> videoKey = GlobalKey();SliverCollapsingWidget(key: videoKey,tag: tag,heroTag: widget.heroTag,)),),class SliverCollapsingWidget extends StatelessWidget {final String tag;final String heroTag;final GlobalKey<VideoWidgetState> videoKey;const SliverCollapsingWidget({Key key,this.tag,@required this.videoKey,@required this.heroTag,}) : super(key: key);....child: NftBlurImageWidget(key: videoKey,heroTag: heroTag ?? "",avatarUrl: controller.model?.avatarUrl ?? "",)class NftBlurImageWidget extends StatelessWidget {const NftBlurImageWidget({Key key,@required this.avatarUrl,@required this.backgroundUrl,@required this.heroTag,@required this.videoKey,}) : super(key: key);
修改方法 不要使用自带key ,要使用重命名参数key传递
这篇关于flutter: Another exception was thrown: Multiple widgets used the same GlobalKey的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!