Creating a BMI calculator in flutter: defining BoxConstraints in constraints but it always shows "The named parameter 'constraints' isn't defined. "

Viewed 73
class RoundIconButton extends StatelessWidget {
  
const RoundIconButton(this.icon, this.onPress);

final Function onPress;
final IconData icon;
  @override
  Widget build(BuildContext context) {
    return MaterialButton(
      child: Icon(icon),
      elevation: 3,
      onPressed: onPress,
        **constraints:** BoxConstraints.tightFor(
          width: 56.0,
          height: 56.0,
        ),

    );
  }
}

constraint in bold error:

The named parameter 'constraints' isn't defined. (undefined_named_parameter at [bmi_calculator] lib\input_page.dart:167)

1 Answers

MaterialButton has no property constraints. You should wrap the button in a ConstrainedBox:

ConstrainedBox(
  constraints: const BoxConstraints.tightFor(
    width: 56.0,
    height: 56.0,
  ),
  child: MaterialButton(
    child: Icon(icon),
    elevation: 3,
    onPressed: onPress,
  ),
);
Related