如何给芯片小部件添加固定宽度?

huangapple go评论70阅读模式
英文:

How to add fixed width to a chip widget?

问题

return SizedBox(
width: MediaQuery.of(context).size.width * 0.4,
child: ChoiceChip(
side: BorderSide(color: Color.fromARGB(255, 10, 60, 100)),
backgroundColor: Colors.transparent,
selectedColor: Color.fromARGB(255, 10, 60, 100),
label: Text(
'Free Wifi',
style: isChecked ? _filterButtonTextStyle : _g4LabelNormal,
maxLines: 2,
),
selected: isChecked,
avatar: SvgPicture.asset(
'assets/images/wifi.svg',
width: _filterAmenityIcon,
height: _filterAmenityIcon,
color: isChecked ? _whiteColor : _filterAmenityColor,
),
onSelected: (value) {},
),
);

英文:

I need to give fixed width for the chip widget like this image 如何给芯片小部件添加固定宽度?

but chip width is changing based on label text

return SizedBox(
        width: MediaQuery.of(context).size.width * 0.4,
        child: ChoiceChip(
             side: BorderSide(color: Color.fromARGB(255, 10, 60, 100)),
            backgroundColor: Colors.transparent,
            selectedColor: Color.fromARGB(255, 10, 60, 100),
            label: Text(
              'Free Wifi',
              style: isChecked ? _filterButtonTextStyle : _g4LabelNormal,
              maxLines: 2,
            ),
            selected: isChecked,
            avatar: SvgPicture.asset(
                'assets/images/wifi.svg',
                width: _filterAmenityIcon,
                height: _filterAmenityIcon,
                color: isChecked ? _whiteColor : _filterAmenityColor),
            onSelected: (value) {
            }));

答案1

得分: 1

找到答案。需要为标签指定大小,而不是整个芯片。

return ChoiceChip(
    side: BorderSide(color: Color.fromARGB(255, 10, 60, 100)),
    backgroundColor: Colors.transparent,
    selectedColor: Color.fromARGB(255, 10, 60, 100),
    label: SizedBox(
        width: MediaQuery.of(context).size.width * 0.4,
        child: Text(
            '免费Wifi',
            style: isChecked ? _filterButtonTextStyle : _g4LabelNormal,
            maxLines: 2,
        )),
    selected: isChecked,
    avatar: SvgPicture.asset(
        'assets/images/wifi.svg',
        width: _filterAmenityIcon,
        height: _filterAmenityIcon,
        color: isChecked ? _whiteColor : _filterAmenityColor),
    onSelected: (value) {
    });
英文:

Found the Answer. Need to give size for Label not Entire Chip.

return ChoiceChip(
             side: BorderSide(color: Color.fromARGB(255, 10, 60, 100)),
            backgroundColor: Colors.transparent,
            selectedColor: Color.fromARGB(255, 10, 60, 100),
            label: SizedBox(width:MediaQuery.of(context).size.width * 0.4,
               child: Text(
                  'Free Wifi',
                  style: isChecked ? _filterButtonTextStyle : _g4LabelNormal,
                  maxLines: 2,
               )),
            selected: isChecked,
            avatar: SvgPicture.asset(
                'assets/images/wifi.svg',
                width: _filterAmenityIcon,
                height: _filterAmenityIcon,
                color: isChecked ? _whiteColor : _filterAmenityColor),
            onSelected: (value) {
            });

答案2

得分: 0

Container(
  width: 120, // 设置固定宽度
  child: ChoiceChip(
    side: BorderSide(color: Color.fromARGB(255, 10, 60, 100)),
    backgroundColor: Colors.transparent,
    selectedColor: Color.fromARGB(255, 10, 60, 100),
    label: Text(
      '免费Wifi',
      style: isChecked ? _filterButtonTextStyle : _g4LabelNormal,
      maxLines: 2,
    ),
    selected: isChecked,
    avatar: SvgPicture.asset(
      'assets/images/wifi.svg',
      width: _filterAmenityIcon,
      height: _filterAmenityIcon,
      color: isChecked ? _whiteColor : _filterAmenityColor,
    ),
    onSelected: (value) {
    
    },
  ),
)
英文:

> Try below code :

Container(
  width: 120, // Se fixed width
  child: ChoiceChip(
    side: BorderSide(color: Color.fromARGB(255, 10, 60, 100)),
    backgroundColor: Colors.transparent,
    selectedColor: Color.fromARGB(255, 10, 60, 100),
    label: Text(
      'Free Wifi',
      style: isChecked ? _filterButtonTextStyle : _g4LabelNormal,
      maxLines: 2,
    ),
    selected: isChecked,
    avatar: SvgPicture.asset(
      'assets/images/wifi.svg',
      width: _filterAmenityIcon,
      height: _filterAmenityIcon,
      color: isChecked ? _whiteColor : _filterAmenityColor,
    ),
    onSelected: (value) {
    
    },
  ),
)

huangapple
  • 本文由 发表于 2023年7月24日 18:33:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753615.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定