简体   繁体   English

Flutter - 滚动列表视图时如何获得圆角边框?

[英]Flutter - How to get Rounded border when scrolling listview?

I'm having listview with chips in bottom of the Column.我在列底部有带芯片的列表视图。

In first image from starting in listview its in circular shape but in the end its shows as rectangle.在从列表视图开始的第一个图像中,它是圆形的,但最后它显示为矩形。

第一张图片

When scrolling the listview Chip 1 day is overflow.(Second Image).滚动列表视图芯片 1 天时溢出。(第二张图片)。

第二张图片

I want both side bottom need to circular, How to achieve?我想两边底都需要圆形,怎么实现? Thanks in Advance.提前致谢。

My Code我的代码

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(),
                      ),
                    )
                  ],
                ),
              )

Chip Function芯片功能

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;
}

The BoxDecoration in the Container will only show the rounded corners as a visual feature. ContainerBoxDecoration只会将圆角显示为视觉特征。 If you want to actually clip the contents to within those rounded corners with no overflow, you want to surround the container in a ClipRRect .如果您想将内容实际剪辑到那些圆角内而不会溢出,您需要将容器包围在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(
      ...
    ),
  ),
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM