类型'int'不是颤振中'key'错误的'String'类型的子类型
Posted
技术标签:
【中文标题】类型\'int\'不是颤振中\'key\'错误的\'String\'类型的子类型【英文标题】:type 'int' is not a subtype of type 'String' of 'key' error in flutter类型'int'不是颤振中'key'错误的'String'类型的子类型 【发布时间】:2020-08-11 22:02:23 【问题描述】:我有一个列表,其中列出了分配给用户的所有任务,如下所示
@override
void initState()
crudObj.getassignedData().then((results)
setState(()
Task = results;
);
);
super.initState();
@override
Widget build(BuildContext context)
return Scaffold(
drawer: newdrawer(),
appBar: newappbar(),
body: _TaskList(),
floatingActionButton: FloatingActionButton(
foregroundColor: Colors.black54,
backgroundColor: Colors.blue,
elevation: 0,
child: Icon(Icons.add),
onPressed: ()
addDialog(context);
,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
// ignore: non_constant_identifier_names
Widget _TaskList()
if (Task != null)
return ListView.builder(
itemCount: Task.documents.length,
padding: EdgeInsets.all(5.0),
itemBuilder: (context, i)
return new ListTile(
title: Text(Task.documents[i].data['Title']),
subtitle: Text(Task.documents[i].data['Summary']),
onTap: ()
Navigator.push(context,
MaterialPageRoute(builder: (context)=>
taskdetail(Task.documents[i])
)
);
,
);
,
);
else
return Text('Loading, Please wait..');
每个任务在点击时都应该打开一个详细信息页面。
class _taskdetailState extends State<taskdetail>
@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text('Details'),
),
body: ListView.builder(itemBuilder: (context,i)
return ListTile(
title: Text(widget.documents[i]['Title']),
);
),
);
我收到此错误:
I/flutter ( 5594): The following assertion was thrown building:
I/flutter ( 5594): type 'int' is not a subtype of type 'String' of 'key'
I/flutter ( 5594):
I/flutter ( 5594): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 5594): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 5594): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 5594): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter ( 5594):
I/flutter ( 5594): When the exception was thrown, this was the stack:
I/flutter ( 5594): #0 _taskdetailState.build.<anonymous closure> (package:taskmanager/screens/taskdetail.dart:23:39)
I/flutter ( 5594): #1 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:446:15)
I/flutter ( 5594): #2 SliverMultiBoxAdaptorElement._build.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1260:67)
I/flutter ( 5594): #3 _HashMap.putIfAbsent (dart:collection-patch/collection_patch.dart:139:29)
I/flutter ( 5594): #4 SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1260:26)
I/flutter ( 5594): #5 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1273:55)
I/flutter ( 5594): #6 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2412:19)
I/flutter ( 5594): #7 SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1266:11)
I/flutter ( 5594): #8 RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:354:23)
I/flutter ( 5594): #9 RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1823:58)
I/flutter ( 5594): #10 PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:875:15)
I/flutter ( 5594): #11 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1823:13)
I/flutter ( 5594): #12 RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:343:5)
I/flutter ( 5594): #13 RenderSliverMultiBoxAdaptor.addInitialChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:427:5)
I/flutter ( 5594): #14 RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:78:12)
I/flutter ( 5594): #15 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #16 RenderSliverEdgeInsetsPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:134:11)
I/flutter ( 5594): #17 RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:373:11)
I/flutter ( 5594): #18 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #19 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:410:13)
I/flutter ( 5594): #20 RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1367:12)
I/flutter ( 5594): #21 RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1285:20)
I/flutter ( 5594): #22 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #23 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #24 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #25 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #26 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #27 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #28 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #29 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #30 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #31 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #32 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #33 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #34 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #35 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #36 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #37 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #38 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #39 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #40 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #41 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:163:11)
I/flutter ( 5594): #42 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:477:7)
I/flutter ( 5594): #43 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:232:7)
I/flutter ( 5594): #44 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:391:14)
I/flutter ( 5594): #45 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #46 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #47 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #48 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #49 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1232:11)
I/flutter ( 5594): #50 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #51 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #52 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #53 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #54 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #55 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #56 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #57 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #58 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #59 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #60 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #61 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #62 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #63 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter ( 5594): #64 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #65 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3166:14)
I/flutter ( 5594): #66 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter ( 5594): #67 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:505:15)
I/flutter ( 5594): #68 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1584:7)
I/flutter ( 5594): #69 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:844:18)
I/flutter ( 5594): #70 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:344:19)
I/flutter ( 5594): #71 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:774:13)
I/flutter ( 5594): #72 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
I/flutter ( 5594): #73 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
I/flutter ( 5594): #74 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
I/flutter ( 5594): #75 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)
I/flutter ( 5594): #79 _invoke (dart:ui/hooks.dart:259:10)
I/flutter ( 5594): #80 _drawFrame (dart:ui/hooks.dart:217:3)
I/flutter ( 5594): (elided 3 frames from package dart:async)
【问题讨论】:
我已经运行了你上面的代码,但没有任何结构错误。您应该提供有关Task
数据存储类型的详细信息。所以我可以使用“任务”数据解决您的问题。
【参考方案1】:
你可以试试,
title: Text("$Task.documents[i].data['Title']"),
subtitle: Text("$Task.documents[i].data['Summary']"),
【讨论】:
我能够运行 listview 文件而没有任何错误。错误出现在第二个屏幕任务详细信息中。 当我点击列表视图时它不会进入详细页面而是显示上述错误 在详细信息页面中,您传递的是单个数据而不是列表。你可以使用Text("$widget.documents.data['Title']")
获取数据。
得到同样的错误''type 'int' is not a subtype of type 'String' of 'key' error in flutter''
taskdetail
类的构造函数获取哪种类型的数据?打印你在构造函数中得到的数据并告诉我。以上是关于类型'int'不是颤振中'key'错误的'String'类型的子类型的主要内容,如果未能解决你的问题,请参考以下文章
在骇客新闻中的颤振小部件测试中,类型“int”不是“String”类型的子类型
未处理的异常:'String' 类型不是'index' 的'int' 类型的子类型问题 Dart 和颤振