参数类型 'void Function()?' 无法分配给参数类型 'void Function()'

The argument type 'void Function()?' can't be assigned to the parameter type 'void Function()'

我收到错误:无法将参数类型 'Function?' 分配给参数类型 '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.');
      }
    });
  }

错误函数。

onPressed: _isFrontImageSelected
                            ? null
                            : () {
                                openCamera("FRONT");
                              }

请帮助我。

error opencamera

无法在此处分配 null

onPressed: _isFrontImageSelected
                            ? null
                            : () {
                                openCamera("FRONT");
                              }

null改成空函数,像这样

onPressed: _isFrontImageSelected
                            ? (){}
                            : () {
                                openCamera("FRONT");
                              }

这会很好用。