提问者:小点点

参数类型'Function'不能分配给参数类型'void Function(bool)?


 Widget _buildSwitchListTile(
     String title,
     String description,
      bool currentValue, 
      VoidCallback updateValue) {
    return SwitchListTile(
      value: currentValue,
      title: Text(title),
      subtitle: Text(description),
      onChanged: updateValue,
    );
  

共2个答案

匿名用户

你可以使用这个:

最终无效函数()?onTap;

如果你愿意,那个函数传递了一些数据,你可以这样使用它:

最终无效功能(bool)?onTap;

匿名用户

SwitchListTileonChanged在回调时提供一个可空的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,
    );