SizedBox(
height: 500.h,
child:
categories[_selectIndex].categoryName != ""
? CarCategoryView(
categoryId: categories[_selectIndex].id)
: Text(
'No car added yet',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15.sp,
color: tdGrey),
))
I want to make SizeBox
expanded because I do not know how much the height will be
I try to put sizeBox.expand
, expanded, flexible, and all does not work. Anyone know any library or code to fix this?
This is not recommended but it may be able to fix your issue.
Could you try to replace the SizedBox widget with IntrinsicHeight to see if it resolves your issue?
Like this:
OLD -
SizedBox(
height: 500.h,
child:
categories[_selectIndex].categoryName != ""
? CarCategoryView(
categoryId: categories[_selectIndex].id)
: Text(
'No car added yet',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15.sp,
color: tdGrey),))
UPDATED -
IntrinsicHeight(
child:
categories[_selectIndex].categoryName != ""
? CarCategoryView(
categoryId: categories[_selectIndex].id)
: Text(
'No car added yet',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15.sp,
color: tdGrey),))
But you need to limit the usage of this in your entire app because it is considered an expensive widget due to its pre-computational workload before the actual build of the widget.
It may be unnoticeable during the early stage of a start-up project, but when the project gets larger. It could affect the performance if you used it too much. To learn more, just visit this flutter documentation about IntrinsicHeight: IntrinsicHeight class