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

7

The argument type 'Future<dynamic>' can't be assigned to the parameter type 'void Function()'

REPLACE THIS:
onPressed: Navigator.push(...)

WITH THIS:
onPressed: () => Navigator.push(...)
Posted by: Guest on October-28-2020
0

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

class DrawerItem extends StatelessWidget {
    
      final String text;
      final VoidCallback onPressed;
    
      const DrawerItem({Key key, this.text, this.onPressed}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return FlatButton(
          child: Text(
            text,
            style: TextStyle(
              fontWeight: FontWeight.w600,
              fontSize: 18.0,
            ),
          ),
          onPressed: onPressed,
        );
      }
    }
Posted by: Guest on March-08-2022

Code answers related to "The argument type 'Function' can't be assigned to the parameter type 'void Function()?'."

Browse Popular Code Answers by Language