How can I increase the height of container according to data I am getting from API. Height of container should depend upon the data we do not know.
Here's my code:
Padding(
padding: EdgeInsets.only(
left: screenWidth * 0.05,
right: screenWidth * 0.05,
top: screenHeight * 0.06,
),
child: Container(
width: double.infinity,
height: cardHeight,
decoration: BoxDecoration(
color: CustomColor.bordercolor,
borderRadius: BorderRadius.circular(screenWidth * 0.05),
border: Border.all(
color: CustomColor.textfieldcolor,
width: screenWidth * 0.005,
),
),
// child: Padding(
// padding: EdgeInsets.only(top: screenHeight * 0.16),
// child:
// ),
child: Flexible(
child: ListView(
// physics: NeverScrollableScrollPhysics(),
// shrinkWrap: true,
children: [
if (!isTrue)
for (int i = 0; i < widget.couponDetails.length; i++)
Padding(
padding: EdgeInsets.only(
left: screenWidth * 0.065,
),
child: Row(
children: [
Expanded(
child: Text(
widget.couponDetails[i],
style: StyeleConstants.normalblacktextstyle400,
),
),
],
),
),
],
),
),
),
),
i tried different approaches but still it is not working.
The answer is short: Don't impose dimensions constraints.
By default, containers and many other widgets try to be big enough to fit their children unless you have already predefined a dimension constraints.
Container( width: double.infinity, height: cardHeight)
Container( width: double.infinity,)
There are other suggestions that will work, such as wrapping that container with a Flexible
if it was inside a Column
.
The idea revolves around not providing a fixed dimension to that container.
Hope it helps you.