I am putting height for Container equal to 40, but it gets the height of parent Container. I think the ListView.builder is stretching its children, cause if i replace that with a row of that Container(look at the code) it works as expected.
import 'package:flutter/material.dart';
class PaymentScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(body: SafeArea(child: Column(children: [
Container(alignment: Alignment.center, height: 200,
child: ListView.builder(scrollDirection: Axis.horizontal, shrinkWrap: true,
itemBuilder: (BuildContext context, int index) =>
/// this Container is stretching, even it has definite height
Container(alignment: Alignment.center, margin: EdgeInsets.all(8), padding: EdgeInsets.all(8), color: Colors.amber,
/// this width is not listening to me!
width: 40, height: 40,
child: Text('${index + 1}'),),
itemCount: 31,),),],),),);
}
}
question from:
https://stackoverflow.com/questions/65938719/height-of-container-is-stretching-in-flutter-even-if-i-put-smaller-value 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…