【发布时间】:2021-11-04 22:51:54
【问题描述】:
我想保持列表视图构建器上方的容器固定,并让列表视图滚动。但是当我实现以下代码时,它显示了 renderflex 溢出问题。
代码:
List<String> companynames = [
'Delloite',
'Google',
'Amazon',
'Apple',
'Tata',
'Wipro',
'Tesla',
'Cupid',
'Pfizer',
'Mango',
'Reliance',
'Titan',
'Toyota',
'Maruti',
'Volkswagen',
'Suzuki'
];
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
body: Column(
//mainAxisSize: MainAxisSize.max,
children: [
Stack(
children: <Widget>[
Container(
color: kbluePrimaryColor,
height: MediaQuery.of(context).size.height * 0.2,
),
Expanded(
child: Padding(
padding: EdgeInsets.only(
left: 20.0,
right: 20.0,
top: MediaQuery.of(context).size.height * 0.12,
),
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
//physics: NeverScrollableScrollPhysics(),
itemCount: companynames.length,
itemBuilder: (context, index) {
return Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(15))),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
companynames[index],
style: TextStyle(
color: kblackPrimaryColor,
fontSize:
MediaQuery.of(context).size.width * 0.06,
fontWeight: FontWeight.bold,
),
),
),
);
}),
),
)
],
),
],
),
);
}
我希望蓝色容器固定,列表视图的第一项与蓝色容器重叠一半并且可滚动。有人能告诉我怎么做吗?
【问题讨论】: