CheckBox 值,我想添加,如果用户选中复选框,那么它应该添加 amount=amount + 18% ,如果没有,那么只添加我的代码
CheckBox value, I want to add ,if user check the checkBox then it should add amount=amount + 18% , if not then only amount my Code
我想添加,如果用户勾选了复选框那么它应该添加 amount=amount + 18%
,如果没有那么唯一的数量
我的代码
final amountController = TextEditingController();
Container(
height: 50.0,
padding: EdgeInsets.only(left: 8),
margin: EdgeInsets.only(top: 8),
decoration:
BoxDecoration(border: Border.all(color: Colors.grey[300], width: 1)),
child: TextFormField(
controller: amountController,
decoration: new InputDecoration(
border: InputBorder.none,
hintStyle: new TextStyle(color: Colors.grey[500]),
hintText: "Assesment Amount",
fillColor: Colors.transparent,
),
keyboardType: TextInputType.number,
),
);
//=======复选框代码============
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来获取复选框的状态。如果 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;
});
}
int amount=0;
if (checkBoxValue){
amount = int.parse(amountController.text) + int.parse(amountController.text)*18/100;
}
else {
amount = int.parse(amountController.text);
}
我想添加,如果用户勾选了复选框那么它应该添加 amount=amount + 18%
,如果没有那么唯一的数量
我的代码
final amountController = TextEditingController();
Container(
height: 50.0,
padding: EdgeInsets.only(left: 8),
margin: EdgeInsets.only(top: 8),
decoration:
BoxDecoration(border: Border.all(color: Colors.grey[300], width: 1)),
child: TextFormField(
controller: amountController,
decoration: new InputDecoration(
border: InputBorder.none,
hintStyle: new TextStyle(color: Colors.grey[500]),
hintText: "Assesment Amount",
fillColor: Colors.transparent,
),
keyboardType: TextInputType.number,
),
);
//=======复选框代码============
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来获取复选框的状态。如果 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;
});
}
int amount=0;
if (checkBoxValue){
amount = int.parse(amountController.text) + int.parse(amountController.text)*18/100;
}
else {
amount = int.parse(amountController.text);
}