Home > Software engineering >  The argument type 'void Function()?' can't be assigned to the parameter type 'vo
The argument type 'void Function()?' can't be assigned to the parameter type 'vo

Time:05-18

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.

error opencamera

CodePudding user response:

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.

  • Related