flutter - 如何在 Flutter 中创建带有图像的单选按钮
解决方案
您可以尝试这种方法:
int _value = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
children: <Widget>[
GestureDetector(
onTap: () => setState(() => _value = 0),
child: Container(
height: 56,
width: 56,
color: _value == 0 ? Colors.grey : Colors.transparent,
child: Icon(Icons.call),
),
),
SizedBox(width: 4),
GestureDetector(
onTap: () => setState(() => _value = 1),
child: Container(
height: 56,
width: 56,
color: _value == 1 ? Colors.grey : Colors.transparent,
child: Icon(Icons.message),
),
),
],
),
),
);
}
推荐阅读
- c# - 如何将公共变量的值传递给另一个脚本
- reactjs - 我可以传递具有额外结构价值的道具吗?
- selenium - 删除所有以前的数据后,如何获取“While”循环的最后更新值
- asp.net - 子应用的动态 url 链接
- flask - 如何使另一个 dockerized (react/typescript) 应用程序可以访问 dockerized flask 应用程序?
- python - TensorFlow 批处理问题
- php - 在 Ubuntu 16.04 上安装 php5.6-redis
- c# - 如何在 Syncfusion Gridview 中更改列标题字体大小?
- json - 将字段映射到 fromjson dart
- r - 如何从大列表中提取元素