I have a widget that displays a checkbox. The checkboxes display days of the week. I am curious to know how I can use the values below in another function? For example, how can I know in another function what the user has selected in terms of a week day?
Here is my checkbox widget code:
bool monVal = false;
bool tuVal = false;
bool wedVal = false;
bool thurVal = false;
bool friVal = false;
bool satVal = false;
bool sunVal = false;
Widget checkbox(String title, bool boolValue) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(title),
Checkbox(
value: boolValue,
onChanged: (bool value) {
/// manage the state of each value
setState(() {
switch (title)
{
case "Mon":
monVal = value;
print(value);
break;
case "Tu":
tuVal = value;
print(value);
break;
case "Wed":
wedVal = value;
print(value);
break;
case "Thur":
thurVal = value;
print(value);
break;
case "Fri":
friVal = value;
print(value);
break;
case "Sat":
satVal = value;
print(value);
break;
case "Sun":
sunVal = value;
print(value);
break;
}
});
},
)
],
);
}
the print(value) is pointless.. I just tried that to see if I could get the day of the week selected, but its only going to return true or false.
Many thanks friends
Aucun commentaire:
Enregistrer un commentaire