type \'bool\' is not a subtype of type \'double\'我在使用ListView.builderinside时遇到错误ExpansionTile。
我能够看到扩展图块,但是当我单击扩展图块时,我收到了如上所述的错误。
\n这是我的带有扩展图块的应用程序的屏幕截图 -
\n\n这是扩展列表时抛出错误的屏幕截图 -
\n\n下面是我的整个代码和错误日志。
\nimport \'package:flutter/material.dart\';\n\nvoid main() => runApp(MyApp());\n\n// Colors\n\nvar mainColor = Color(0xFF35393C);\nvar bgColor = Color(0xFF30313C);\n\nclass MyApp extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n return new MaterialApp(\n title: \'List of Items\',\n theme: new ThemeData(brightness: Brightness.dark),\n home: new Home(title: \'List of Items\'),\n );\n }\n}\n\nclass Home extends StatefulWidget {\n Home({Key key, this.title}) : super(key: key);\n\n final String title;\n @override\n _HomeState createState() => _HomeState();\n}\n\nclass _HomeState extends State<Home> {\n bool success = false;\n\n final ScrollController _scrollController = ScrollController();\n\n static List<String> categories = [\'Test1\', \'Test1\', \'Test2\', \'Test3\', \'Test4\', \'Test5\', \'Test6\', \'Test7\', \'Test8\', \'Test9\', \'Test10\'];\n static List<List<String>> subCategories = [\n [\n "Approved",\n "Not Approved",\n "Under Test"\n ],\n [\n "The maximum level of brightness",\n "Screen darker",\n "Make screen the darkest"\n ],\n [\n "Mute",\n "Unmute"\n ],\n [\n "Open the roof",\n "Close the roof"\n ],\n [\n "Windows1",\n "Windows2",\n "Windows3",\n "Windows4",\n "Open windows",\n "Close windows"\n ],\n [\n "Ac1",\n "Ac2",\n "Ac3",\n "Ac4",\n "Ac5",\n "Ac6",\n "Ac7",\n "Ac8",\n "Ac9",\n "Ac10",\n "Highest fan speed",\n "Lowest fan speed"\n ],\n [\n "Open setting",\n "Help"\n ],\n [\n "Windows1",\n "Windows2",\n "Windows3",\n "Windows4",\n "Open windows",\n "Close windows"\n ],\n [\n "Ac1",\n "Ac2",\n "Ac3",\n "Ac4",\n "Ac5",\n "Ac6",\n "Ac7",\n "Ac8",\n "Ac9",\n "Ac10",\n "Highest fan speed",\n "Lowest fan speed"\n ],\n [\n "Approved",\n "Not Approved",\n "Under Test",\n "Ac1",\n "Ac2",\n "Ac3",\n "Ac4",\n "Ac5",\n "Ac6",\n "Ac7",\n "Ac8",\n "Ac9",\n "Ac10",\n "Highest fan speed",\n "Lowest fan speed",\n "Windows1",\n "Windows2",\n "Windows3",\n "Windows4",\n "Open windows",\n "Close windows"\n ],\n [\n "Windows1",\n "Windows2",\n "Windows3",\n "Windows4",\n "Open windows",\n "Close windows"\n ]\n ];\n static List<bool> activeCategories = List.filled(categories.length, false);\n\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n backgroundColor: bgColor,\n appBar: new AppBar(\n title: new Center(child: new Text(widget.title, textAlign: TextAlign.center)),\n ),\n body: ListView.builder(\n itemCount: categories.length,\n itemBuilder: (context, index) {\n return ExpansionTile(\n title: Text(categories.elementAt(index)),\n key: PageStorageKey<String>(categories.elementAt(index)),\n children:<Widget>[\n ListView.builder(\n controller: _scrollController,\n scrollDirection: Axis.horizontal,\n shrinkWrap: true,\n itemCount: subCategories.length,\n itemBuilder: (context, subIndex){\n return ListTile(\n title: new Text(subCategories.elementAt(index).elementAt(subIndex)),\n );\n },\n ),\n ],\n );\n }\n ),\n );\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n下面是我在执行代码时得到的日志。
\nI/flutter (21943): \xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY WIDGETS LIBRARY \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nI/flutter (21943): The following assertion was thrown building ListView(scrollDirection: horizontal,\nI/flutter (21943): ScrollController#eaec6(no clients), shrinkWrap: shrink-wrapping, dependencies: [Directionality,\nI/flutter (21943): MediaQuery]):\nI/flutter (21943): type \'bool\' is not a subtype of type \'double\'\nI/flutter (21943): \nI/flutter (21943): Either the assertion indicates an error in the framework itself, or we should provide substantially\nI/flutter (21943): more information in this error message to help you determine and fix the underlying cause.\nI/flutter (21943): In either case, please report this assertion by filing a bug on GitHub:\nI/flutter (21943): https://github.com/flutter/flutter/issues/new?template=BUG.md\nI/flutter (21943): \nI/flutter (21943): The relevant error-causing widget was:\nI/flutter (21943): ListView file:///path_to_file/main.dart:198:26\nI/flutter (21943): \nI/flutter (21943): When the exception was thrown, this was the stack:\nI/flutter (21943): #0 ScrollPosition.restoreScrollOffset (package:flutter/src/widgets/scroll_position.dart:384:20)\nI/flutter (21943): #1 new ScrollPosition (package:flutter/src/widgets/scroll_position.dart:108:7)\nI/flutter (21943): #2 new ScrollPositionWithSingleContext (package:flutter/src/widgets/scroll_position_with_single_context.dart:57:8)\nI/flutter (21943): #3 ScrollController.createScrollPosition (package:flutter/src/widgets/scroll_controller.dart:233:12)\nI/flutter (21943): #4 ScrollableState._updatePosition (package:flutter/src/widgets/scrollable.dart:332:29)\nI/flutter (21943): #5 ScrollableState.didChangeDependencies (package:flutter/src/widgets/scrollable.dart:341:5)\nI/flutter (21943): #6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4376:12)\nI/flutter (21943): #7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)\nI/flutter (21943): #8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)\nI/flutter (21943): #9 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)\nI/flutter (21943): #10 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)\nI/flutter (21943): #11 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)\nI/flutter (21943): #12 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)\nI/flutter (21943): #13 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)\nI/flutter (21943): #14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)\nI/flutter (21943): #15 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)\nI/flutter (21943): #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)\nI/flutter (21943): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)\nI/flutter (21943): #18 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)\nI/flutter (21943): #19 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)\nI/flutter (21943): #20 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)\nI/flutter (21943): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)\nI/flutter (21943): #22 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5161:32)\nI/flutter (21943): #23 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5561:17)\nI/flutter (21943): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)\nI/flutter (21943): #25 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)\nI/flutter (21943): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)\nI/flutter (21943): #27 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)\nI/flutter (21943): #28 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)\nI/flutter (21943): #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)\nI/flutter (21943): #30 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)\nI/flutter (21943): #31 StatelessElement.update (package:flutter/src/widgets/framework.dart:4298:5)\nI/flutter (21943): #32 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)\nI/flutter (21943): #33 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)\nI/flutter (21943): #34 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)\nI/flutter (21943): #35 StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5)\nI/flutter (21943): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)\nI/flutter (21943): #37 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)\nI/flutter (21943): #38 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)\nI/flutter (21943): #39 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2432:33)\nI/flutter (21943): #40 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:773:20)\nI/flutter (21943): #41 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)\nI/flutter (21943): #42 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)\nI/flutter (21943): #43 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)\nI/flutter (21943): #44 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)\nI/flutter (21943): #48 _invoke (dart:ui/hooks.dart:259:10)\nI/flutter (21943): #49 _drawFrame (dart:ui/hooks.dart:217:3)\nI/flutter (21943): (elided 3 frames from package dart:async)\nI/flutter (21943): \nI/flutter (21943): \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\n\nRun Code Online (Sandbox Code Playgroud)\n
Jor*_*eña 10
这对我来说工作:
...键:PageStorageKey ...
来源: https ://github.com/flutter/flutter/issues/36539#issuecomment-561848176
试试这个:)
class _HomeState extends State<Home> {
bool success = false;
final ScrollController _scrollController = ScrollController();
static List<String> categories = ['Test1', 'Test1', 'Test2', 'Test3', 'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9', 'Test10'];
static List<List<String>> subCategories = [
[
"Approved",
"Not Approved",
"Under Test"
],
[
"The maximum level of brightness",
"Screen darker",
"Make screen the darkest"
],
[
"Mute",
"Unmute"
],
[
"Open the roof",
"Close the roof"
],
[
"Windows1",
"Windows2",
"Windows3",
"Windows4",
"Open windows",
"Close windows"
],
[
"Ac1",
"Ac2",
"Ac3",
"Ac4",
"Ac5",
"Ac6",
"Ac7",
"Ac8",
"Ac9",
"Ac10",
"Highest fan speed",
"Lowest fan speed"
],
[
"Open setting",
"Help"
],
[
"Windows1",
"Windows2",
"Windows3",
"Windows4",
"Open windows",
"Close windows"
],
[
"Ac1",
"Ac2",
"Ac3",
"Ac4",
"Ac5",
"Ac6",
"Ac7",
"Ac8",
"Ac9",
"Ac10",
"Highest fan speed",
"Lowest fan speed"
],
[
"Approved",
"Not Approved",
"Under Test",
"Ac1",
"Ac2",
"Ac3",
"Ac4",
"Ac5",
"Ac6",
"Ac7",
"Ac8",
"Ac9",
"Ac10",
"Highest fan speed",
"Lowest fan speed",
"Windows1",
"Windows2",
"Windows3",
"Windows4",
"Open windows",
"Close windows"
],
[
"Windows1",
"Windows2",
"Windows3",
"Windows4",
"Open windows",
"Close windows"
]
];
static List<bool> activeCategories = List.filled(categories.length, false);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: bgColor,
appBar: new AppBar(
title: new Center(child: new Text(widget.title, textAlign: TextAlign.center)),
),
body: ListView.builder(
itemCount: categories.length,
itemBuilder: (context, index) {
return ExpansionTile(
title: Text(categories.elementAt(index)),
key: PageStorageKey<String>(categories.elementAt(index)),
children: subCategories[index].map((text){
return ListTile(title: Text(text),);
}).toList(),
);
}
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望它有帮助...