Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't assign argument type Function #21

Open
chamilaja-yawardana opened this issue Jun 6, 2021 · 1 comment
Open

Can't assign argument type Function #21

chamilaja-yawardana opened this issue Jun 6, 2021 · 1 comment

Comments

@chamilaja-yawardana
Copy link

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
Copy link

quekyj commented Dec 4, 2022

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,
      ),
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants