The argument type 'void Function()?' can't be assigned to the parameter type 'void Function()'
532
can't assign a null
here.
onPressed: _isFrontImageSelected
? null
: () {
openCamera("FRONT");
}
Change the null
to empty function, Like this
onPressed: _isFrontImageSelected
? (){}
: () {
openCamera("FRONT");
}
This will work fine.
Author by
Viandsyahrezah
Updated on January 04, 2023Comments
-
Viandsyahrezah over 1 year
i get Error: The argument type 'Function?' can't be assigned to the parameter type 'void Function(bool?)?'.
late bool _isFrontImageSelected; late bool _isSideImageSelected; @override void initState() { super.initState(); _isFrontImageSelected = false; _isSideImageSelected = false; } Future openCamera(String type) async { if (type == 'FRONT') { frontImage = await ImagePicker().pickImage(source: ImageSource.camera); } else { sideImage = await ImagePicker().pickImage(source: ImageSource.camera); } setState(() { if (frontImage != null) { _isFrontImageSelected = true; // ignore: avoid_print print('front image selected.'); } if (sideImage != null) { _isSideImageSelected = true; // ignore: avoid_print print('side image selected.'); } }); }
Error Function.
onPressed: _isFrontImageSelected ? null : () { openCamera("FRONT"); }
please help me.
-
Daniel Roldán almost 2 yearsThe onPressed attribute, is from a Button or a Custom Widget ?
-
-
Viandsyahrezah almost 2 yearsThank you very much sir. now the error has been successfully recovered
-
Kashif Niaz almost 2 yearsYou are welcome dear. 😊