在我的扑动项目中,过去两天我发现这个错误'_elements.contains(element)': is not true.
,从一开始就一直很好。我很遗憾地说这个,但我不知道这个错误,但我想我错过了导致这个错误的东西。此外,当我热重新加载同一页面时,将填充布局,但会抛出异常。
间歇性地,这也显示了检测到的Duplicate GlobalKeys(),但在开始时情况并非如此。
如果他们之前偶然发现了这些错误,请有人帮助我。我真的不能写一个例子来重现同样的问题。非常感谢。
我已经提供了如下错误详情:
Performing hot reload...
I/flutter (22248): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════
I/flutter (22248): The following assertion was thrown building
TickerMode(mode: disabled):
I/flutter (22248): 'package:flutter/src/widgets/framework.dart': Failed
assertion: line 1766 pos 12:
I/flutter (22248): '_elements.contains(element)': is not true.
I/flutter (22248):
I/flutter (22248): Either the assertion indicates an error in the framework
itself, or we should provide substantially
I/flutter (22248): more information in this error message to help you
determine and fix the underlying cause.
I/flutter (22248): In either case, please report this assertion by filing a
bug on GitHub:
I/flutter (22248): https://github.com/flutter/flutter/issues/new
I/flutter (22248):
I/flutter (22248): When the exception was thrown, this was the stack:
I/flutter (22248): #2 _InactiveElements.remove
(package:flutter/src/widgets/framework.dart:1766:12)
I/flutter (22248): #3 Element._retakeInactiveElement
(package:flutter/src/widgets/framework.dart:2850:29)
I/flutter (22248): #4 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:2873:32)
I/flutter (22248): #5 Element.updateChild
(package:flutter/src/widgets/framework.dart:2688:12)
I/flutter (22248): #6 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #7 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #8 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #9 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #10 RenderObjectElement.updateChildren
(package:flutter/src/widgets/framework.dart:4262:32)
I/flutter (22248): #11 _TheatreElement.update
(package:flutter/src/widgets/overlay.dart:508:17)
I/flutter (22248): #12 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #13 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #14 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #15 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #16 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #17 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #18 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #19 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #20 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #21 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4535:14)
I/flutter (22248): #22 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #23 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #24 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #25 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #26 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #27 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4535:14)
I/flutter (22248): #28 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #29 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4535:14)
I/flutter (22248): #30 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #31 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #32 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #33 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #34 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #35 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #36 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #37 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #38 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #39 SingleChildRenderObjectElement.update
(package:flutter/src/widgets/framework.dart:4535:14)
I/flutter (22248): #40 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #41 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #42 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #43 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3607:5)
I/flutter (22248): #44 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #45 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #46 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #47 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3607:5)
I/flutter (22248): #48 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #49 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #50 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #51 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3607:5)
I/flutter (22248): #52 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #53 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #54 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #55 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3607:5)
I/flutter (22248): #56 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #57 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #58 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #59 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #60 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #61 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #62 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #63 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #64 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #65 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #66 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #67 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #68 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #69 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #70 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #71 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #72 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #73 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #74 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #75 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #76 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #77 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #78 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #79 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #80 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #81 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #82 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #83 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #84 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #85 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #86 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #87 StatelessElement.update
(package:flutter/src/widgets/framework.dart:3607:5)
I/flutter (22248): #88 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #89 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #90 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #91 StatefulElement.update
(package:flutter/src/widgets/framework.dart:3682:5)
I/flutter (22248): #92 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #93 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #94 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #95 ProxyElement.update
(package:flutter/src/widgets/framework.dart:3792:5)
I/flutter (22248): #96 Element.updateChild
(package:flutter/src/widgets/framework.dart:2677:15)
I/flutter (22248): #97 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3557:16)
I/flutter (22248): #98 Element.rebuild
(package:flutter/src/widgets/framework.dart:3446:5)
I/flutter (22248): #99 BuildOwner.buildScope
(package:flutter/src/widgets/framework.dart:2246:33)
I/flutter (22248): #100
BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&Renderer
Binding&WidgetsBinding.drawFrame
(package:flutter/src/widgets/binding.dart:580:20)
I/flutter (22248): #101
BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&Renderer
Binding._handlePersistentFrameCallback
(package:flutter/src/rendering/binding.dart:200:5)
I/flutter (22248): #102
BindingBase&SchedulerBinding._invokeFrameCallback
(package:flutter/src/scheduler/binding.dart:713:15)
I/flutter (22248): #103 BindingBase&SchedulerBinding.handleDrawFrame
(package:flutter/src/scheduler/binding.dart:649:9)
I/flutter (22248): #104
BindingBase&SchedulerBinding&GestureBinding&ServicesBinding&Renderer
Binding.scheduleWarmUpFrame.<anonymous closure>
(package:flutter/src/rendering/binding.dart:286:20)
I/flutter (22248): #106 _Timer._runTimers (dart:isolate-
patch/dart:isolate/timer_impl.dart:367)
I/flutter (22248): #107 _Timer._handleMessage (dart:isolate-
patch/dart:isolate/timer_impl.dart:401)
I/flutter (22248): #108 _RawReceivePortImpl._handleMessage
(dart:isolate-patch/dart:isolate/isolate_patch.dart:163)
I/flutter (22248): (elided 3 frames from class _AssertionError and
package dart:async-patch)
I/flutter (22248):
══════════════════════════════════════════════════════════════════════════
══════════════════════════
Reloaded 0 of 492 libraries in 823ms.
我已经在我的应用程序中包含了一个我想要做的示例。
main.dart
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:untitled3/secondwidget.dart';
void main() {
runApp(
new Example(),
);
}
class Example extends StatefulWidget {
@override
_ExampleState createState() => new _ExampleState();
}
class _ExampleState extends State<Example> {
int noOfBranches;
@override
void initState() {
super.initState();
getCount();
}
void getCount() {
print('list builder count is ${noOfBranches}');
}
@override
Widget build(BuildContext context) {
setState(() {
noOfBranches = 2;
});
return new MaterialApp(
home: new Scaffold(
body: new ListView.builder(
itemCount: noOfBranches,
itemBuilder: (BuildContext context, int index) {
return new Card(
child: new FlatButton(
onPressed: (() {
Navigator.push(
context,
new MaterialPageRoute(
builder: (_) => new SecondWidget()));
}),
child: new Text('Next Widget')),
);
}),
),
);
}
}
secondwidget.dart
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class SecondWidget extends StatefulWidget {
@override
_SecondWidgetState createState() => new _SecondWidgetState();
}
class _SecondWidgetState extends State<SecondWidget> {
@override
Widget build(BuildContext context) {
return new Container(
child: new Text('Second Widget'),
);
}
}
如果setState()
声明在示例main.dart文件中给出,我在应用程序中看不到错误
@override
Widget build(BuildContext context) {
setState(() {
noOfBranches = 2;
});
.....
}
但如果我在setState()
函数中声明getCount()
,我只会看到此错误。
我不太确定为什么会这样。
我实际上已经坚持这个错误两天了,任何帮助都会非常感激。
非常感谢, 鳅
答案 0 :(得分:0)
我认为我通过在
中声明 using System.Collections;
ICollection keyCollections = dict.Keys;
ICOllection valueCollections = dict.Values;
String[] myKeys = new String[dict.Count];
String[] myValues = new String[dict.Count];
keyCollections.CopyTo(myKeys,0);
valueCollections.CopyTo(myValues,0);
for(int i=0; i<dict.Count; i++)
{
Console.WriteLine("Key: " + myKeys[i] + "Value: " + myValues[i]);
}
Console.ReadKey();
来解决错误
setState()
现在应用程序运行绝对正常,没有任何问题。
但是,如果我有更多的建议,我将不胜感激,因为我是编程新手,并且非常乐意了解更多信息。
唯一的问题是 @override
Widget build(BuildContext context) {
setState(() {
noOfBranches = 2;
});
print('noof branches inside widget build = $noOfBranches');
.....
}
正在修改上下文,当单击按钮调用另一个小部件时,它会抛出此错误消息。
非常感谢, 鳅。
答案 1 :(得分:0)
为什么不在noOfBranches
方法中设置initState
变量?
@override
void initState() {
super.initState();
noOfBranches = 2;
}