0
    import 'package:flutter/material.dart';

class ReusableCard extends StatelessWidget {

  final Color? colour;
  final Widget? cardChild;
  final Function? onPress;

  ReusableCard({this.colour, this.cardChild, this.onPress});


  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: **onPress**,
      child: Container(
        child: cardChild,
        margin: EdgeInsets.all(15.0),
        decoration: BoxDecoration(
            color: colour,
            borderRadius: BorderRadius.circular(10.0)),
      ),
    );

  }
}

lib/reusable_card.dart:15:14: Error: The argument type 'Function?' can't be assigned to the parameter type 'void Function()?'.

  • 'Function' is from 'dart:core'. onTap: onPress, ^ What could be the error and how should I use the function onPress instead?
  • Does this answer your question? [The argument type 'Function' can't be assigned to the parameter type 'void Function()?' after null safety](https://stackoverflow.com/questions/64484113/the-argument-type-function-cant-be-assigned-to-the-parameter-type-void-funct) – Md. Yeasin Sheikh Feb 14 '22 at 10:09

1 Answers1

1

Use VoidCallback? instead like so: final VoidCallback? onPress;

Or use final void Function()? onPress;

Josteve
  • 11,459
  • 1
  • 23
  • 35