flutter - Flutter - 执行计算的单选按钮
问题描述
例如,如果用户输入逗号等特殊字符,应用程序将显示最后一个值,则存在一个小问题。如何使其显示零值或其他显示错误的通知。
注意我在文本字段中使用“keyboardType:TextInputType.number”,除此之外,有时单击按钮后,它会第一次显示值为零。解决方法是我必须单击其他单选按钮才能显示值
例子:
https://i.stack.imgur.com/MnkQ1.png
代码:
void handleTsTBRadioWater(int option) {
setState(() {
radioValue = option;
});
switch (radioValue) {
case 1:
output = input * 0.06763;
break;
case 2:
output = input * 0.202884136;
break;
}
}
ListTile tb = ListTile(
title: const Text('Tablespoon'),
leading: Radio(
value: 1,
groupValue: radioValue,
onChanged: (handleTsTBRadioWater),
),
);
ListTile ts = ListTile(
title: const Text('Teaspoon'),
leading: Radio(
value: 2,
groupValue: radioValue,
onChanged: (handleTsTBRadioWater),
),
);
Container calcBtn = Container(
child: ButtonTheme(
minWidth: 40.0,
height: 40.0,
child: RaisedButton(
child: Text("Calculate Water"),
color: Colors.blueAccent,
onPressed: () {
AlertDialog dialog = AlertDialog(
content: Text(
"${input.toStringAsFixed(2)} Gram : ${output.toStringAsFixed(2)} Teaspoon"));
showDialog(builder: (context) => dialog, context: context);
},
),
),
);
解决方案
推荐阅读
- powershell - Powershell 使用 ENV 变量转换字符串
- c++ - unordered_map Vs map Vs array - 内存分析
- jquery - 是否可以弯曲滑块(html css)
- cuda - 我可以让 nvlink 列出它实际使用的库吗?
- python - 如何与 discord.py 中的附加图像进行交互
- javascript - 如何将参数从javascript传递给Ajax函数
- javascript - 突出显示的输入文本不会在按键时更新
- python - Python,macOS - 如何创建文件的查找器别名?
- css - 更改输入焦点上的边框
- google-chrome - 仅 Chrome 上的 SVG 平铺间隙