Flutter 复选框值,我想添加,如果用户选中复选框,则应添加amount=amount+;18%,如果不是的话,那么只计算我的代码
我想添加,如果用户选中复选框,则应添加Flutter 复选框值,我想添加,如果用户选中复选框,则应添加amount=amount+;18%,如果不是的话,那么只计算我的代码,flutter,dart,flutter-layout,flutter-dependencies,flutter-test,Flutter,Dart,Flutter Layout,Flutter Dependencies,Flutter Test,我想添加,如果用户选中复选框,则应添加amount=amount+18%,如果不是,则添加唯一的金额 我的代码 //=======复选框代码============ Container( child: Checkbox( value: checkBoxValue, onChanged: (value) { setState(() { checkBoxValue = value; }); }), ); /
amount=amount+18%
,如果不是,则添加唯一的金额
我的代码
//=======复选框代码============
Container(
child: Checkbox(
value: checkBoxValue,
onChanged: (value) {
setState(() {
checkBoxValue = value;
});
}),
);
//==========插入按钮代码=================
else if (update == false && imageFile != null) {
setState(() {
name = titleController.text;
nameList.add(name);
amountList.add(amountController.text);
img.add(imageFile);
titleController.clear();
amountController.clear();
imageFile = null;
});
}
首先,我们将把字符串中的写入量解析为整数,这样我们可以执行计算,然后我们可以使用布尔checkBoxValue获取checkbox的状态。如果checkBoxValue==true,我们将把输入金额的18%添加到金额变量中,否则我们将按原样添加金额
else if (update == false && imageFile != null) {
setState(() {
name = titleController.text;
nameList.add(name);
int _amount = int.parse(amountController.text);
_amount = checkBoxValue ? _amount + ((18 / _amount) * 100) : _amount;
amountList.add(_amount);
img.add(imageFile);
titleController.clear();
amountController.clear();
imageFile = null;
});
}
首先,我们将把字符串中的写入量解析为整数,这样我们可以执行计算,然后我们可以使用布尔checkBoxValue获取checkbox的状态。如果checkBoxValue==true,我们将把输入金额的18%添加到金额变量中,否则我们将按原样添加金额
else if (update == false && imageFile != null) {
setState(() {
name = titleController.text;
nameList.add(name);
int _amount = int.parse(amountController.text);
_amount = checkBoxValue ? _amount + ((18 / _amount) * 100) : _amount;
amountList.add(_amount);
img.add(imageFile);
titleController.clear();
amountController.clear();
imageFile = null;
});
}
金额=支票价值?金额+(金额*(18/100)):金额;金额=支票价值?金额+(金额*(18/100)):金额;请不要只发布代码作为答案,还要解释代码的作用以及它是如何解决问题的。带有解释的答案通常质量更高,并且更有可能吸引更多的选票。请不要只发布代码作为答案,还要解释代码的作用以及它如何解决问题。带有解释的答案通常质量更高,更容易吸引选票。
int amount=0;
if (checkBoxValue){
amount = int.parse(amountController.text) + int.parse(amountController.text)*18/100;
}
else {
amount = int.parse(amountController.text);
}