import 'package:flutter/material.dart';
import 'package:ourchatapp/constants.dart';
class RoundedButton extends StatelessWidget {
final String text;
final Function press;
final Color color, textColor;
const RoundedButton({
Key? key,
required this.text,
required this.press,
this.color = kPrimaryColor,
this.textColor = Colors.white,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
margin: EdgeInsets.symmetric(vertical: 10),
width: size.width * 0.8,
child: ClipRRect(
borderRadius: BorderRadius.circular(29),
child: newElevatedButton(),
),
);
}
Widget newElevatedButton() {
return ElevatedButton(
child: Text(
text,
style: TextStyle(color: textColor),
),
onPressed: press,
style: ElevatedButton.styleFrom(
primary: color,
padding: EdgeInsets.symmetric(horizontal: 40, vertical: 20),
textStyle: TextStyle(
color: textColor, fontSize: 14, fontWeight: FontWeight.w500)),
);
}
}
I want to design my own button, when I add it to the relevant pages, I get such an error and when I click the button, it does not switch between the pages. I have created login and sign up buttons on the welcome screen, but when I click on these buttons, they do not switch to the relevant pages. please help me
CodePudding user response:
You have declared the press as Function type so you change -
onPressed: press,
to -
onPressed: () => press(),
these way you will call the function and it will change the page.
CodePudding user response:
Try to change press
type from Function
to VoidCallback
, so your press parameter should look like this:
final VoidCallback press
Or try this:
onPressed : press.call()