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


import 'package:flutter/material.dart';

class Answer extends StatelessWidget {
  final Function selectHandler;


  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      color: Colors.pink,
      child: ElevatedButton(
        child: Text('Answer 1'),
        onPressed: selectHandler,

[screenshot of vscode][1]

I got this code that I use from a Dart (flutter) YouTube course (that is from 2019) and i get an error on the last "selectHandler" (after onPressed) -> "The argument type ‘Function’ can’t be assigned to the parameter type ‘void Function()?’" I don’t really understand because it is working well in the video.
I am pretty sure that the course is too old but if you can help me that could be cool. Thanks ! (PS: my flutter doctor is good)



final Function selectHandler;


final void Function() selectHandler;

see this ref doc

Answered By – navylover

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published.