在type 'bool' is not a subtype of type 'double'
内使用ListView.builder
时出现错误ExpansionTile
。
我可以看到扩展图块,但是当我单击扩展图块时,出现了如上所述的错误。
这是我的带有扩展图块的应用的屏幕截图-
这是扩展列表时抛出错误的屏幕截图-
下面是我的整个代码和错误日志。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
// Colors
var mainColor = Color(0xFF35393C);
var bgColor = Color(0xFF30313C);
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'List of Items',
theme: new ThemeData(brightness: Brightness.dark),
home: new Home(title: 'List of Items'),
);
}
}
class Home extends StatefulWidget {
Home({Key key, this.title}) : super(key: key);
final String title;
@override
_HomeState createState() => _HomeState();
}
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:<Widget>[
ListView.builder(
controller: _scrollController,
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: subCategories.length,
itemBuilder: (context, subIndex){
return ListTile(
title: new Text(subCategories.elementAt(index).elementAt(subIndex)),
);
},
),
],
);
}
),
);
}
}
下面是我在执行代码时得到的日志。
I/flutter (21943): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (21943): The following assertion was thrown building ListView(scrollDirection: horizontal,
I/flutter (21943): ScrollController#eaec6(no clients), shrinkWrap: shrink-wrapping, dependencies: [Directionality,
I/flutter (21943): MediaQuery]):
I/flutter (21943): type 'bool' is not a subtype of type 'double'
I/flutter (21943):
I/flutter (21943): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (21943): more information in this error message to help you determine and fix the underlying cause.
I/flutter (21943): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (21943): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (21943):
I/flutter (21943): The relevant error-causing widget was:
I/flutter (21943): ListView file:///path_to_file/main.dart:198:26
I/flutter (21943):
I/flutter (21943): When the exception was thrown, this was the stack:
I/flutter (21943): #0 ScrollPosition.restoreScrollOffset (package:flutter/src/widgets/scroll_position.dart:384:20)
I/flutter (21943): #1 new ScrollPosition (package:flutter/src/widgets/scroll_position.dart:108:7)
I/flutter (21943): #2 new ScrollPositionWithSingleContext (package:flutter/src/widgets/scroll_position_with_single_context.dart:57:8)
I/flutter (21943): #3 ScrollController.createScrollPosition (package:flutter/src/widgets/scroll_controller.dart:233:12)
I/flutter (21943): #4 ScrollableState._updatePosition (package:flutter/src/widgets/scrollable.dart:332:29)
I/flutter (21943): #5 ScrollableState.didChangeDependencies (package:flutter/src/widgets/scrollable.dart:341:5)
I/flutter (21943): #6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4376:12)
I/flutter (21943): #7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (21943): #8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (21943): #9 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (21943): #10 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (21943): #11 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (21943): #12 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter (21943): #13 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter (21943): #14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (21943): #15 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
I/flutter (21943): #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter (21943): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter (21943): #18 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
I/flutter (21943): #19 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
I/flutter (21943): #20 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
I/flutter (21943): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
I/flutter (21943): #22 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5161:32)
I/flutter (21943): #23 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5561:17)
I/flutter (21943): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
I/flutter (21943): #25 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
I/flutter (21943): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
I/flutter (21943): #27 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
I/flutter (21943): #28 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
I/flutter (21943): #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (21943): #30 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (21943): #31 StatelessElement.update (package:flutter/src/widgets/framework.dart:4298:5)
I/flutter (21943): #32 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
I/flutter (21943): #33 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (21943): #34 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (21943): #35 StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5)
I/flutter (21943): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
I/flutter (21943): #37 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
I/flutter (21943): #38 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter (21943): #39 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2432:33)
I/flutter (21943): #40 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:773:20)
I/flutter (21943): #41 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
I/flutter (21943): #42 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
I/flutter (21943): #43 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
I/flutter (21943): #44 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)
I/flutter (21943): #48 _invoke (dart:ui/hooks.dart:259:10)
I/flutter (21943): #49 _drawFrame (dart:ui/hooks.dart:217:3)
I/flutter (21943): (elided 3 frames from package dart:async)
I/flutter (21943):
I/flutter (21943): ════════════════════════════════════════════════════════════════════════════════════════════════════
答案 0 :(得分:1)
试试看:)
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(),
);
}
),
);
}
}
我希望这对您有帮助...
答案 1 :(得分:0)
为我工作:
...键: PageStorageKey ...
来源: https://github.com/flutter/flutter/issues/36539#issuecomment-561848176