我遇到了一个问题,乱七八糟
我在最大课程中,遇到了一个问题。我有4个由Builder创建的开关:
//here are variables used later to pass data into builder
bool _glutenFree = false;
bool _vegetarian = false;
bool _vegan = false;
bool _lactoseFree = false;
Widget _buildSwitchListTile(
String title,
String description,
bool currentValue,
Function(bool) updateValue,
) {
return SwitchListTile(
title: Text(title),
value: _glutenFree,
subtitle: Text(description),
onChanged: updateValue,
);
}
当我尝试单击第二,第三,第4个开关时,什么也不会发生。 但是,当我尝试单击第一个开关时,所有四个开关。
这是_buildSwitchlisttile的使用方式:
_buildSwitchListTile(
'Gluten-free',
'Only include gluten-free meals.',
_glutenFree,
(newValue) {
setState(
() {
_glutenFree = newValue;
},
);
},
),
_buildSwitchListTile(
'Lactose-free',
'Only include Lactose-free meals.',
_lactoseFree,
(newValue) {
setState(
() {
_lactoseFree = newValue;
},
);
},
),
_buildSwitchListTile(
'Vegetarian',
'Only include Vegetarian meals.',
_vegetarian,
(newValue) {
setState(
() {
_vegetarian = newValue;
},
);
},
),
_buildSwitchListTile(
'Vegan',
'Only include Vegan meals.',
_vegan,
(newValue) {
setState(
() {
_vegan = newValue;
},
);
},
),
我知道Max的课程现在已经过时了,我通常会自己分析问题,但是这里的一切似乎都是合乎逻辑的。有人遇到过类似问题吗?
I'm on the max course, and ran into a problem. I have 4 switches which are created by builder:
//here are variables used later to pass data into builder
bool _glutenFree = false;
bool _vegetarian = false;
bool _vegan = false;
bool _lactoseFree = false;
Widget _buildSwitchListTile(
String title,
String description,
bool currentValue,
Function(bool) updateValue,
) {
return SwitchListTile(
title: Text(title),
value: _glutenFree,
subtitle: Text(description),
onChanged: updateValue,
);
}
When I try to click the 2nd, 3rd, 4th switch, nothing happens.
But when I try to click the first one, all four switch.
here is how _buildSwitchListTile is used:
_buildSwitchListTile(
'Gluten-free',
'Only include gluten-free meals.',
_glutenFree,
(newValue) {
setState(
() {
_glutenFree = newValue;
},
);
},
),
_buildSwitchListTile(
'Lactose-free',
'Only include Lactose-free meals.',
_lactoseFree,
(newValue) {
setState(
() {
_lactoseFree = newValue;
},
);
},
),
_buildSwitchListTile(
'Vegetarian',
'Only include Vegetarian meals.',
_vegetarian,
(newValue) {
setState(
() {
_vegetarian = newValue;
},
);
},
),
_buildSwitchListTile(
'Vegan',
'Only include Vegan meals.',
_vegan,
(newValue) {
setState(
() {
_vegan = newValue;
},
);
},
),
I know that the Max's course is a bit outdated now,I usually analyze the problems myself, but everything seems logical here. Has anyone ever had a similar problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将_glutenfree更改为CurrentValue
change _glutenFree to currentValue