【发布时间】:2021-06-18 22:02:28
【问题描述】:
我正在创建一个允许芯片在水平空间上水平滚动的功能。为了实现这个功能,我们在 SingleChildScrollView 中开发了 Row 组件。当用户按下其中一个筹码时,我想要筹码按钮的值,onpressed 对我不起作用??
here is my Build method where is use the chips
@override
Widget build(BuildContext context) {
print(widget.useridforinfo);
print(widget.usertypeforinfo);
return Scaffold(
key: _key,
appBar: AppBar(
title: Text(widget.title),
centerTitle: true,
elevation: 0.0,
backgroundColor: Colors.orange.shade900,
),
body: Column(
children: <Widget>[
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: rowChips(),
),
],
),
);
}
rowChips(){
return Row(
children: <Widget>[
chipForRow("Aids Abeba",Color(0xFFff8a65)),
chipForRow("Adama",Color(0xFF9575cd)),
chipForRow("Hawasssa",Color(0xFF4db6ac)),
chipForRow("Bishoftu",Color(0xFF5cda65)),
chipForRow("Aids Abeba",Color(0xFFff8a65)),
chipForRow("Adama",Color(0xFF9575cd)),
chipForRow("Hawasssa",Color(0xFF4db6ac)),
chipForRow("Bishoftu",Color(0xFF5cda65)),
],
);
}
here is my method to Create the chips
Widget chipForRow(String label, Color color){
return Container(
margin: EdgeInsets.all(6.0),
child: Chip(
labelPadding: EdgeInsets.all(5.0),
avatar: CircleAvatar(
backgroundColor: Colors.grey.shade900,
child: Text(label[0].toUpperCase())
),
label: Text(
label,
style: TextStyle(
color: Colors.white,
),
),
backgroundColor: color,
elevation: 6.0,
shadowColor: Colors.grey[60],
padding: EdgeInsets.all(6.0),
),
);
}
【问题讨论】: