pomoworko.com
pomoworko.com

Reputation: 1118

How to fix 'RaisedButton' error in Flutter using CustomButton?

I'm encountering the following errors in my Flutter project while trying to implement a CustomButton widget:

  1. "The method RaisedButton isn't defined for the type CustomButton"
  2. "The expression doesn't evaluate to a function, so it can't be invoked"
  3. "Undefined name text"

Code:

(dart)
  class CustomButton extends StatelessWidget {
  final Function onTap;
  final String Text;
  const CustomButton({required this.onTap, required this.Text});

  @override
  Widget build(BuildContext context) {
    return ButtonTheme(
      minWidth: 200,
      child: RaisedButton(
      onPressed: onTap,
      child: Text(text,style: TextStyle(fontSize: 15),
      ),
    ),
    );
  }
}

How to solve the issues? Thank you!.

Upvotes: 0

Views: 4246

Answers (1)

Sujan Gainju
Sujan Gainju

Reputation: 4769

  1. You have extra ")". Try removing one and it should work. Also, prefer using ElevatedButton. RaisedButton is depreciated.
  2. Function onTap is not a function. Replace it with Function()? onTap
  3. You have type (final String Text). make it final String text

Upvotes: 1

Related Questions