Home > Software design >  Flutter - The getter 'build' isn't defined in a superclass of 'CustomButton'
Flutter - The getter 'build' isn't defined in a superclass of 'CustomButton'

Time:12-05

I'm trying to create a custom button widget in Flutter. It should be based on the ElevatedButton widget. Somehow I get this Error message:

The getter 'build' isn't defined in a superclass of 'CustomButton'. Try correcting the name to the name of an existing getter, or defining a getter or field named 'build' in a superclass.

But the superclass definitely has the build method. Here's the code:

class CustomButton extends ElevatedButton {
  @override
  final VoidCallback onPressed;
  final Widget child;

  @override
  const CustomButton({required this.onPressed, required this.child})
      : super(onPressed: onPressed, child: child);

  Widget build(BuildContext context) {
    return Theme(
      data: Theme.of(context).copyWith(
          buttonTheme: Theme.of(context).buttonTheme.copyWith(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(15.0)))),
      child: Builder(builder: super.build),
    );
  }
}

CodePudding user response:

There is no build method in ElevatedButton, which extends ButtonStyleButton. ButtonStyleButton is s StatefulWidget, which has no build method neither.

CodePudding user response:

Put @override before the build widget

  • Related