Flutter - 滚动列表视图时如何获得圆角边框?
Flutter - How to get Rounded border when scrolling listview?
我的列表视图在列底部有条码。
从列表视图开始的第一张图片是圆形的,但最后它显示为矩形。
滚动列表视图时 Chip 1 天溢出。(第二张图片)。
我想要两侧底部都需要圆形,如何实现?提前致谢。
我的代码
Container(
padding: EdgeInsets.only(
top: 16.0,
),
width: MediaQuery.of(context).size.width,
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: Colors.white),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(""),
Container(
height: 35,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(12.0),
bottomRight: Radius.circular(12.0)),
color:
Theme.of(context).chipTheme.backgroundColor),
child: ListView(
scrollDirection: Axis.horizontal,
children: getChoiceChips(),
),
)
],
),
)
芯片功能
getChoiceChips() {
List<Widget> choiceChipList = [];
List<String> choiceString = [
'1 Day',
'1 Week',
'1 Month',
'3 Months',
'1 Year'
];
for (String choice in choiceString) {
choiceChipList.add(Padding(
padding: const EdgeInsets.only(left: 2.0, right: 2.0),
child: ChoiceChip(
label: Text(choice),
selected: choice == selectedChoice,
onSelected: (newSelectedChoice) {
setState(() {
print(selectedChoice);
print(newSelectedChoice);
selectedChoice = choice;
print(selectedChoice);
print(choice);
});
},
),
));
}
return choiceChipList;
}
BoxDecoration
中的Container
只会将圆角显示为视觉特征。如果您想实际将内容剪辑到没有溢出的圆角内,您需要将容器包围在 ClipRRect
.
中
ClipRRect(
borderRadius: BorderRadius.circular(12.0),
child: Container(
padding: EdgeInsets.only(top: 16.0),
width: MediaQuery.of(context).size.width,
height: 100,
decoration: BoxDecoration(color: Colors.white),
child: Column(
...
),
),
),
我的列表视图在列底部有条码。
从列表视图开始的第一张图片是圆形的,但最后它显示为矩形。
滚动列表视图时 Chip 1 天溢出。(第二张图片)。
我想要两侧底部都需要圆形,如何实现?提前致谢。
我的代码
Container(
padding: EdgeInsets.only(
top: 16.0,
),
width: MediaQuery.of(context).size.width,
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: Colors.white),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(""),
Container(
height: 35,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(12.0),
bottomRight: Radius.circular(12.0)),
color:
Theme.of(context).chipTheme.backgroundColor),
child: ListView(
scrollDirection: Axis.horizontal,
children: getChoiceChips(),
),
)
],
),
)
芯片功能
getChoiceChips() {
List<Widget> choiceChipList = [];
List<String> choiceString = [
'1 Day',
'1 Week',
'1 Month',
'3 Months',
'1 Year'
];
for (String choice in choiceString) {
choiceChipList.add(Padding(
padding: const EdgeInsets.only(left: 2.0, right: 2.0),
child: ChoiceChip(
label: Text(choice),
selected: choice == selectedChoice,
onSelected: (newSelectedChoice) {
setState(() {
print(selectedChoice);
print(newSelectedChoice);
selectedChoice = choice;
print(selectedChoice);
print(choice);
});
},
),
));
}
return choiceChipList;
}
BoxDecoration
中的Container
只会将圆角显示为视觉特征。如果您想实际将内容剪辑到没有溢出的圆角内,您需要将容器包围在 ClipRRect
.
ClipRRect(
borderRadius: BorderRadius.circular(12.0),
child: Container(
padding: EdgeInsets.only(top: 16.0),
width: MediaQuery.of(context).size.width,
height: 100,
decoration: BoxDecoration(color: Colors.white),
child: Column(
...
),
),
),