简体   繁体   English

如何在颤动的大小框中添加两个参数?

[英]How to add two parameter within sized box in flutter?

I wanted to change the size of the raised Button.. So i created a sized box and added width and height as I wanted and wrapped the raised button inside the sized box... After I did that the button sticks to the left corner only.. So I used the align widget to keep it in center but since I made to child under the sized box it became an error.. So how to rectify this?!我想改变凸起按钮的大小..所以我创建了一个大小的框并根据需要添加宽度和高度并将凸起的按钮包裹在大小的框内......在我这样做之后按钮只粘在左角.. 所以我使用 align 小部件将其保持在中心,但由于我在大小框下方制作了 child 它成为一个错误.. 那么如何纠正这个?!

SizedBox(
               width: 100.0,
               height: 50.0,
                 child: Align(
                 alignment: Alignment.center,
               ),
               child: RaisedButton(
               child: Center(child: Text("Sign Up", style: TextStyle(color: Colors.white.withOpacity(.7)),)),
                  color: Colors.blue[800],
              onPressed: () {
               Navigator.push(
                context, 
               MaterialPageRoute(builder: (context)=> UserPage()));
               }
              ),
             )

try like this,试试这样

     SizedBox(
          height: 50.0,              
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              RaisedButton(
                  child: Center(
                      child: Text(
                    "Sign Up",
                    style: TextStyle(color: Colors.white.withOpacity(.7)),
                  )),
                  color: Colors.blue[800],
                  onPressed: () {
                    Navigator.push(context,
                        MaterialPageRoute(builder: (context) => UserPage()));
                  }),
            ],
          ),
        )

Simply wrap with center widget简单地用中心小部件包裹

Center(
  child: SizedBox(
             width: 100.0,
             height: 50.0,                  
             child: RaisedButton(
             child: Center(child: Text("Sign Up", style: TextStyle(color: Colors.white.withOpacity(.7)),)),
                color: Colors.blue[800],
            onPressed: () {

             }
            )
    ),
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM