Widget _buildSwitchListTile(
String title,
String description,
bool currentValue,
VoidCallback updateValue) {
return SwitchListTile(
value: currentValue,
title: Text(title),
subtitle: Text(description),
onChanged: updateValue,
);
你可以使用这个:
最终无效函数()?onTap;
如果你愿意,那个函数传递了一些数据,你可以这样使用它:
最终无效功能(bool)?onTap;
SwitchListTile
onChanged
在回调时提供一个可空的bool。尝试更改Function(bool)updateValue
Widget _buildSwitchListTile(
String title,
String description,
bool currentValue,
Function(bool) updateValue) {
return SwitchListTile(
value: currentValue,
title: Text(title),
subtitle: Text(description),
onChanged: updateValue,
);