Home > Software engineering >  error not nulled flutter function help me
error not nulled flutter function help me

Time:04-22

Expanded constroiBotoes ({String? caracterDaTecla, Color corTecla = Colors.white, Function? onPress}){
    return Expanded(
      child: ElevatedButton(
        child: Text(caracterDaTecla!),
        style: ElevatedButton.styleFrom(
            textStyle: TextStyle(
               fontSize: 28,
               color: corTecla
            ),
        ),
        onPressed : onPress,
      ),
    );
  }

lib/main.dart:170:21: Error: The argument type 'Function?' can't be assigned to the parameter type 'void Function()?'.

  • 'Function' is from 'dart:core'. onPressed : onPress,

CodePudding user response:

Use the VoidCallback type that is used at the onPressed argument of the ElevatedButton.

Expanded constroiBotoes({
    String? caracterDaTecla, 
    Color corTecla = Colors.white, 
    VoidCallback? onPressed,    // <---- HERE
  }){
    return Expanded(
      child: ElevatedButton(
        child: Text(caracterDaTecla!),
        style: ElevatedButton.styleFrom(
          textStyle: TextStyle(
              fontSize: 28,
              color: corTecla
          ),
        ),
        onPressed: onPressed,
      ),
    );
  }
  • Related