title: Passing a function as parameter in flutter with null safety
body: <p>After upgrading to Flutter 1.25.0-8.1.pre null safety is enabled by default and I started to modify the code of my project. Everything is working fine except functions passed as parameters like in the following example:</p>
  <pre><code>class AppBarIcon extends StatelessWidget {
    final IconData icon;
    final Function onPressed;
    const AppBarIcon({Key? key, required this.icon, required this.onPressed}) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return CupertinoButton(
        child: Icon(icon, size: 28, color: Colors.white),
        onPressed: onPressed,
      );
    }
  }
  </code></pre>
  <p><em>onPressed</em> is a required parameter so it cannot be null but nevertheless I get an error when trying to pass the function to the <em>CupertinoButton</em>:</p>
  <p><code>The argument type 'Function' can't be assigned to the parameter type 'void Function()?'.</code></p>
  <p>I am already searching quite long for an answer and a possible solution but I haven't found one yet. Any help would be much appreciated.</p>