如何解决Flutter Provider 调用Element.updata(widget)报错
想模仿Android的fragment切换效果,通过fragment动态更新FrameLayout布局。但是在项目中使用provider时,调用element时会出现异常。更新(协变小部件、新小部件)。
异常捕获==========
veg(i)
简化后的代码如下(可以直接运行)。 点击顶部按钮切换widget
The following assertion was thrown while handling a gesture:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 3439 pos 7: '_lifecycleState == _ElementLifecycle.active
&& widget != null
&& newWidget != null
&& newWidget != widget
&& depth != null
&& Widget.canUpdate(widget,newWidget)': is not true.
Either the assertion indicates an error in the framework itself,or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case,please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
When the exception was thrown,this was the stack:
#2 Element.update (package:flutter/src/widgets/framework.dart:3439:7)
#3 StatefulElement.update (package:flutter/src/widgets/framework.dart:4751:11)
#4 _HomePageState.itemWidget.<anonymous closure>.<anonymous closure> (package:flutter_app/a/ui/page/home_page.dart:192:25)
#5 BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2473:15)
#6 _HomePageState.itemWidget.<anonymous closure> (package:flutter_app/a/ui/page/home_page.dart:191:27)
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#2d601
debugOwner: GestureDetector
state: ready
won arena
finalPosition: Offset(120.0,195.0)
finalLocalPosition: Offset(40.0,33.5)
button: 1
sent tap down
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。