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.

Share:
532
Viandsyahrezah
Author by

Viandsyahrezah

Updated on January 04, 2023

Comments

  • Viandsyahrezah
    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.

    error opencamera

    • Daniel Roldán
      Daniel Roldán almost 2 years
      The onPressed attribute, is from a Button or a Custom Widget ?
  • Viandsyahrezah
    Viandsyahrezah almost 2 years
    Thank you very much sir. now the error has been successfully recovered
  • Kashif Niaz
    Kashif Niaz almost 2 years
    You are welcome dear. 😊