Reputation: 1
**======== Exception caught by widgets library ======================================================= The following _CastError was thrown building Builder: Null check operator used on a null value **
productmodel.dart
final List? size;
main.dart
final Product? product;
List _sizeList=[];
`if(widget.product.size!.isNotEmpty){`
`_sizeList=widget.product.size!;`
`}`
Container(
height: 80,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _sizeList!.length,
itemBuilder: (context,index){
print(_sizeList![index]);
return Text(_sizeList![index]);
}),
),
Upvotes: 0
Views: 751
Reputation: 71
You use null-assertion operator (1). For example here:
`if(widget.product.size!.isNotEmpty){`
It means, that you are sure, that property size isn't null. But in some place in your code variable appears to be null, and you have corresponding error
Upvotes: 1