How to create material button class in flutter

117 Views Asked by At

I'm currently creating an application and there's a lot of button that is needed. Is there a proper way to create it?

I tried creating class for it but I've encountered multiple errors while creating it specifically in the Material Page Route part.

1

There are 1 best solutions below

0
On BEST ANSWER

You can use this class anywhere in your application by creating a custom class.

I think a class like this will work for you.

class CustomButton extends StatelessWidget {
const CustomButton({super.key, required this.child, required 
this.onPressed});
final Widget child;
final VoidCallback onPressed;

@override
Widget build(BuildContext context) {
return MaterialButton(
  onPressed: onPressed,
  child: child,
  );
 }
}

You can also use it this way:

CustomButton(
        child: const Text('text'),
        onPressed: () {},
      ),