Widget _buildSwitchListTile(
String title,
String description,
bool currentValue,
VoidCallback updateValue) {
return SwitchListTile(
value: currentValue,
title: Text(title),
subtitle: Text(description),
onChanged: updateValue,
);
Asked
Active
Viewed 47 times
-1

Md. Yeasin Sheikh
- 54,221
- 7
- 29
- 56

umar akhtar
- 1
- 1
-
Does ['Function' can't be assigned to the parameter type 'void Function()?'](https://stackoverflow.com/q/64484113/10157127) answer your question – Md. Yeasin Sheikh Aug 09 '22 at 19:46
-
Im a beginner and i couldn't find my answer there. – umar akhtar Aug 09 '22 at 19:55
2 Answers
0
You can use this:
final void Function()? onTap;
and if you want, that function passed some data, you can use it like this:
final void Function(bool)? onTap;

aminjafari-dev
- 264
- 1
- 17
0
SwitchListTile
onChanged
provide a nullable bool on callback.
Try changing 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,
);

Md. Yeasin Sheikh
- 54,221
- 7
- 29
- 56
-
glad to help, you can check more about [understanding-null-safety](https://dart.dev/null-safety/understanding-null-safety) and find more about [SwitchListTile](https://api.flutter.dev/flutter/material/SwitchListTile-class.html) – Md. Yeasin Sheikh Aug 09 '22 at 20:03