容器中的固定高度在 Flutter 中不起作用

Al *_*hik 1 flutter statelesswidget flutter-widget

容器高度设置为固定 40,但是一旦我在 AppBar() 中使用该小部件,它就会采用所有可能的高度。这是我的自定义小部件的代码,它具有固定的容器高度,

class LPBorderButtonWithIcon extends StatelessWidget {
  final GestureTapCallback onPressed;
  final String text;
  final String iconAsset;
  final Color textColor;

  LPBorderButtonWithIcon(
      {@required this.onPressed,
      @required this.text,
      @required this.textColor,
      @required this.iconAsset});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: onPressed,
        child: Container(
          height: 40,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(25),
              border: Border.all(color: Color(0XFFd8dce1))),
          child: Row(
            children: [
              WidthSizedBox(15),
              Image.asset(
                iconAsset,
                height: 14,
                width: 14,
              ),
              WidthSizedBox(5),
              Text(text,
                  style: TextStyle(
                      color: textColor,
                      fontSize: 12,
                      fontFamily: "GilroyMedium")),
              WidthSizedBox(15),
            ],
          ),
        ));
  }
}
Run Code Online (Sandbox Code Playgroud)

LPBorderButtonWithIcon()我在这个屏幕中使用,

class CreateRulesScreen extends StatefulWidget {
  @override
  _CreateRulesScreenState createState() => _CreateRulesScreenState();
}

class _CreateRulesScreenState extends State<CreateRulesScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        brightness: Brightness.light,
        backgroundColor: Colors.white,
        elevation: 1,
        centerTitle: false,
        titleSpacing: 0.0,
        leading: BackButton(
          color: LPColor.primary,
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
        title: Text(
          "Create Rule",
          style: LPStyle.titleStyle,
        ),
        actions: [
          Container(
            margin: EdgeInsets.only(top: 12, bottom: 12, right: 16),
            child: LPBorderButtonWithIcon(
              onPressed: null,
              text: "Create",
              textColor: Color(0XFF508ff4),
              iconAsset: "images/ic_publish.png",
            ),
          )
        ],
      ),

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

下面是自定义容器采用所有可能高度的结果。请让我知道如何为自定义小部件设置固定高度。

在此输入图像描述

Lui*_*uiz 11

将容器放入对齐中,Aling 将强制容器仅占据所需的空间。

Align(
   child: Container(
   height: 20,
   width: 30,
   color: Colors.white,
  ),
)
Run Code Online (Sandbox Code Playgroud)