我有三个屏幕(我正在对它们进行操作,以便您可以轻松理解),并且所有这些屏幕都相互链接,方法是先从第1页导航到第2页,然后从第2页导航到第3页。最终,我向后拉了Navigaiton.pop。当ı从第2页跳到第1页时,出现此错误
I/flutter (11452): Another exception was thrown: Multiple widgets used the same GlobalKey.
I/flutter (11452): Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 2153 pos 12: 'attached': is not true.
I/flutter (11452): Another exception was thrown: 'package:flutter/src/widgets/heroes.dart': Failed assertion: line 411 pos 14: 'overlayEntry != null': is not true.
I/flutter (11452): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4954 pos 12: '_children.contains(child)': is not true.
I/flutter (11452): Another exception was thrown: Duplicate GlobalKey detected in widget tree.
但是,当ı继续执行第1页到第2页时,则将第2页弹出到第1页。我没有收到任何错误,因此以某种方式链接到了第3页
我在导航中做错了吗?这个错误意味着我没有使用任何全局密钥?
EDİT!!:我发现了一些问题。我在将page3弹出到page2时遇到此错误。我不知道这是什么,但我确实认为这是某种联系:
I/flutter ( 6540): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 6540): The following assertion was thrown while finalizing the widget tree:
I/flutter ( 6540): 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3473 pos 12:
I/flutter ( 6540): '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
I/flutter ( 6540):
I/flutter ( 6540): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 6540): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 6540): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 6540): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter ( 6540):
I/flutter ( 6540): When the exception was thrown, this was the stack:
I/flutter ( 6540): #2 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:3473:12)
I/flutter ( 6540): #3 State.setState (package:flutter/src/widgets/framework.dart:1146:14)
I/flutter ( 6540): #4 WebViewState.dispose (package:aurorav10/Components/WebView.dart:45:5)
I/flutter ( 6540): #5 StatefulElement.unmount (package:flutter/src/widgets/framework.dart:3900:12)
I/flutter ( 6540): #6 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1709:13)
I/flutter ( 6540): #7 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #8 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4848:14)
I/flutter ( 6540): #9 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #10 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #11 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
I/flutter ( 6540): #12 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #13 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #14 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4848:14)
I/flutter ( 6540): #15 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #16 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #17 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4848:14)
I/flutter ( 6540): #18 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #19 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #20 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4848:14)
I/flutter ( 6540): #21 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #22 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #23 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4848:14)
I/flutter ( 6540): #24 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #25 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #26 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
I/flutter ( 6540): #27 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #28 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #29 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
I/flutter ( 6540): #30 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #31 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #32 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
I/flutter ( 6540): #33 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #34 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #35 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4848:14)
I/flutter ( 6540): #36 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #37 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #38 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
I/flutter ( 6540): #39 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #40 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #41 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4848:14)
I/flutter ( 6540): #42 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #43 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #44 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
I/flutter ( 6540): #45 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #46 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #47 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
I/flutter ( 6540): #48 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #49 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #50 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:4848:14)
I/flutter ( 6540): #51 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #52 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #53 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
I/flutter ( 6540): #54 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #55 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #56 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
I/flutter ( 6540): #57 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #58 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
I/flutter ( 6540): #59 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
I/flutter ( 6540): #60 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
I/flutter ( 6540): #61 ListIterable.forEach (dart:_internal/iterable.dart:39:13)
I/flutter ( 6540): #62 _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:1718:25)
I/flutter ( 6540): #63 BuildOwner.finalizeTree.<anonymous closure> (package:flutter/src/widgets/framework.dart:2372:27)
I/flutter ( 6540): #64 BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2204:15)
I/flutter ( 6540): #65 BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:2371:7)
I/flutter ( 6540): #66 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:678:18)
I/flutter ( 6540): #67 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
I/flutter ( 6540): #68 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter ( 6540): #69 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter ( 6540): #70 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter ( 6540): #71 _invoke (dart:ui/hooks.dart:154:13)
I/flutter ( 6540): #72 _drawFrame (dart:ui/hooks.dart:143:3)
I/flutter ( 6540): (elided 2 frames from class _AssertionError)
代码:
第1页:
return OrientationBuilder(builder: (context, orientation) {
return RefreshIndicator(
onRefresh: refreshList,
child: new GridView.builder(
itemCount: dergiler.length,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 1.0,
crossAxisSpacing: 1.0,
childAspectRatio: 0.7),
itemBuilder: (BuildContext context, int index) {
return Container(
alignment: Alignment.center,
child: Dergielemet(dergiler[index], index),
);
},
),
);
});
//this class is on other file but ı put this here to help you see it easly
class Dergielemet extends StatelessWidget {
Dergi dergi;
int indexed;
Dergielemet(this.dergi, this.indexed);
@override
Widget build(BuildContext context) {
return Container(
width: 163.0,
height: 247.0,
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
return DergiDetail(dergi.image,dergi.name,indexed);
}));
},
child: new Container(
width: 163.0,
height: 222.0,
child: new Stack(
children: <Widget>[
new Container(
color: Theme.Colors.dergigray,
width: 163.0,
height: 222.0,
),
new Hero(
key: Key(indexed.toString()+"asd"),
tag: indexed,
child: new Container(
margin: new EdgeInsets.all(6.0),
width: 151.0,
height: 210.1,
decoration: new BoxDecoration(
image: new DecorationImage(
image: NetworkImage(dergi.image),
fit: BoxFit.cover,
),
),
),
),
],
),
),
),
new Stack(
children: <Widget>[
new Container(
width: 163.0,
height: 25.0,
child: new Opacity(
opacity: 0.44,
child: new Container(
width: 163.0,
height: 25.0,
color: Theme.Colors.dergigray,
),
),
),
PAGE2:
return new Stack(children: <Widget>[
new Container(
child: new GestureDetector(
onTap: () {
Navigator.pop(context);
/* Navigator.push(context, MaterialPageRoute(builder: (_) {
return Bottomtab();
}));*/
},
child: new Icon(
Icons.arrow_back_ios,
color: Colors.white,
size: 30.0,
)
),
margin: EdgeInsets.only(top: 24.0, left: 10.0),
),
Column(
children: <Widget>[
// new Container(
// margin: EdgeInsets.only(top: 32.0),
// color: Colors.black,
// width: 211,
// height: 291,
new Container(
decoration: BoxDecoration(
border: new Border.all(color: Colors.black,width: 6.0)
),
margin: EdgeInsets.all(6.0),
child: Hero(
key: Key("sda"),
tag: indexed,
child: new Container(
width: 199.0,
height: 278.0,
decoration: new BoxDecoration(
image: new DecorationImage(
image: new NetworkImage(dergiimage),
fit: BoxFit.cover)),
),
),
),
new Container(height: 29.0),
// İmage is over
new Material(
type: MaterialType.transparency,
child: new Text(
baslik,
style: Theme.TextStyles.detailpagetitle,
)),
// Text is over
new Expanded(
flex: 1,
child: new ListView.builder(
itemCount: details.length,
itemBuilder: (BuildContext ctxt, int index) {
return DetailTile(
details[index].title, details[index].link);
}))
],
),
]);
//Other File
class DetailTile extends StatelessWidget {
String url, title;
DetailTile(this.title, this.url,);
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(5.0),
child: GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
return WebViewPlugin(url);
}));
},
child: Container(
decoration: new BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(25.0),
),
width: 100.0,
height: 41.0,
child: new Row(
children: <Widget>[
new Container(
margin: EdgeInsets.only(left: 4.0,right: 16.0),
height:34,
width: 34,
child: new Center(
child: new Material(type: MaterialType.transparency, child:new Text("B",style: Theme.TextStyles.detailpagetilecapital,)),
),
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15.0),
),
),
new Material(
type: MaterialType.transparency,
child: Text(
"$title",
style: Theme.TextStyles.detailpagetiletitle,
)),
],
),
),
),
);
}
}
第3页:
return new Container(
color: Colors.red,
);