type 'Null' is not a subtype of type 'String'
Error code with the following code:
class ExpandingItems extends StatefulWidget {
final product_detail_name;
final product_detail_price;
final product_detail_picture;
final product_detail_description;
final product_detail_Description_cn;
ExpandingItems({
this.product_detail_name,
this.product_detail_description,
this.product_detail_picture,
this.product_detail_price,
this.product_detail_Description_cn,
});
@override
_ExpandingItemsState createState() => _ExpandingItemsState();
}
class _ExpandingItemsState extends State<ExpandingItems> {
List<bool> _isExpanded = List.generate(1, (_) => false);
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Container(
child: ExpansionPanelList(
expansionCallback: (index, isExpanded) => setState(() {
_isExpanded[index] = !isExpanded;
}),
children: [
for (int i = 0; i < 1; i++)
ExpansionPanel(
body: ListTile(
subtitle: Text(widget.product_detail_Description_cn),
),
headerBuilder: (_, isExpanded) {
return Center(
child: Text("Brand"),
);
},
isExpanded: _isExpanded[i]),
],
),
),
);
}
}
i've changed the format with .tostring but it will only appear the null text instead of the description i've stored.
Performing hot reload... Syncing files to device Android SDK built for x86...
Exception caught by widgets library
The following _TypeError was thrown building ExpandingItems(dirty, state: _ExpandingItemsState#23c38): type 'Null' is not a subtype of type 'String'
The relevant error-causing widget was:
ExpandingItems file:///C:/Users/nick_/StudioProjects/appsome/lib/pages/Product_Details.dart:224:13
When the exception was thrown, this was the stack:
#0 _ExpandingItemsState.build (package:appsome/pages/Product_Details.dart:266:44)
#1 StatefulElement.build (package:flutter/src/widgets/framework.dart:4691:27)
#2 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4574:15)
#3 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4746:11)
#4 Element.rebuild (package:flutter/src/widgets/framework.dart:4267:5)
...
====================================================================================================
Reloaded 1 of 558 libraries in 2.910ms.
widget.product_detail_Description_cn
has value. - Miftakhul Arzakprint(widget.product_detail_Description_cn)
oninitState()
. And please add log error, so other users can solve it easier. - Miftakhul Arzakprint(widget.product_detail_Description_cn)
oninitState()
just to see if your variable has value or null, not to solve the error. What is the result ofprint(widget.product_detail_Description_cn)
?. - Miftakhul Arzak