升高按钮高度不增加

BLB*_*BLB 15 height button dart flutter

由于“凸起”按钮已被弃用,我用“凸起”按钮代替。但我无法增加升高按钮的高度。

class ZuzuButton extends StatelessWidget {
final Function onTapped;
final String name;
final double height;
final TextStyle textStyle;
final double radius;
final List<BoxShadow> shadow;
final Color color;
final bool enable;
ZuzuButton({this.onTapped,@required this.name,
  this.height,this.textStyle,this.radius,this.shadow,this.color,this.enable=true});
@override
Widget build(BuildContext context) {
  return Container(
    height: height==0?48.0:height,
    decoration: new BoxDecoration(
      borderRadius: BorderRadius.circular(radius!=null?radius:30.0),
      border: enable? Border.all(
        width: color!=null?0.0:1.0,
        color: color!=null?color:Color(0x407F16F0),
      ):null,
      boxShadow: enable?(shadow==null?[
        BoxShadow(
          color: Color(0x407F16F0),
          offset: Offset(0.0, 8.0),
          spreadRadius: 0,
          blurRadius: 20,
        ),
      ]:shadow):null,
    ),
    child: ElevatedButton(
      child: Container(
        child: Center(
          child: Text(name,style: textStyle!=null?textStyle:null,),
        ),
        height: height==0?48.0:height,
      ),
      onPressed: enable?onTapped:null,
      style: ButtonStyle(
        elevation:  MaterialStateProperty.resolveWith<double>(
              (Set<MaterialState> states) {
            return 0.0;
          },
        ),
        backgroundColor: MaterialStateProperty.resolveWith<Color>(
              (Set<MaterialState> states) {
            if (states.contains(MaterialState.pressed))
              return Color(0xffF7E86C);
            return enable?(color!=null?color:null):Color(0xffDBD9D2); // Use the component's default.
          },
        ),
        textStyle: MaterialStateProperty.resolveWith<TextStyle>(
              (Set<MaterialState> states) {
            if (states.contains(MaterialState.pressed))
              return ZuzuTopography.FF2_Button_Bold.copyWith(color: Colors.black);
            return ZuzuTopography.FF2_Button_Bold.copyWith(color: Colors.white); // Use the component's default.
          },
        ),
        shape: MaterialStateProperty.resolveWith<OutlinedBorder>(
              (Set<MaterialState> states) {
            // if (states.contains(MaterialState.pressed))
            //   return radius!=null? RoundedRectangleBorder(
            //           borderRadius: BorderRadius.circular(radius),
            //       ):null;
            return RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(radius!=null?radius:30.0),
            ); // Use the component's default.
          },
        ),
      ),

    ),
  );
}
}
Run Code Online (Sandbox Code Playgroud)

我的输出。 在此输入图像描述

如何让这个按钮占据它的容器高度?我在互联网上搜索解决方案,但找不到任何解决方案。我的代码中有什么建议吗?除了升高按钮之外,还有其他替代升高按钮的方法吗?

小智 27

我刚刚开始使用提升按钮。对我来说,我只是用这个来改变高度:

ElevatedButton(
  onPressed: () {},
  style: ElevatedButton.styleFrom(
    minimumSize: Size(width, height) // put the width and height you want, standard ones are 64, 40
  ),
  child: Text("NEXT"),
)
Run Code Online (Sandbox Code Playgroud)


Avi*_*ash 11

您可以用来ConstrainedBox做同样的事情。请参考下面的代码以供参考。

ConstrainedBox(
            constraints: BoxConstraints.tightFor(width: 300, height: 200),
            child: ElevatedButton(
              child: Text('300 x 200'),
              onPressed: () {},
            ),
          ),
Run Code Online (Sandbox Code Playgroud)


小智 9

使用带有宽度和高度参数的 SizeBox。

SizedBox(
      width: double.infinity,
      height: 55.0, 
      child: ElevatedButton(
      ),
    );
Run Code Online (Sandbox Code Playgroud)