英文:
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) {
},
),
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论