londonappbrewery / bmi-calculator-flutter

Learn to Code While Building Apps - The Complete Flutter Development Bootcamp
https://www.appbrewery.co
192 stars 835 forks source link

Can't assign argument type Function #21

Open chamilaja-yawardana opened 3 years ago

chamilaja-yawardana commented 3 years ago

I am getting this error "The argument type 'Function' can't be assigned to the parameter type 'void Function()?"

`class BottomButton extends StatelessWidget { BottomButton({required this.onTap, required this.buttonTitle});

final Function onTap; final String buttonTitle;

@override Widget build(BuildContext context) { return GestureDetector( onTap: onTap, child: Container( padding: EdgeInsets.only(bottom: 10), child: Center( child: Text( buttonTitle, style: kLargeButtonTextStyle, ), ), color: kBottomContainerColour, margin: EdgeInsets.only(top: 10), width: double.infinity, height: kBottomContainerHeight, ), ); } }`

quekyj commented 1 year ago

Try this:

class ReusableCard extends StatelessWidget {
  Color colour;
  Widget? cardChild;
  VoidCallback onPress;

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

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