天天看點

flutter FlatButton基本使用和設定按鈕大小

FlatButton 按鈕在預設情況下是有大小的,FlatButton 是沒有提供設定按鈕大小問題的,如何設定大小那麼就在包裹SizedBox

flutter FlatButton基本使用和設定按鈕大小
SizedBox(
              width: 50,
              height: 32,
              child: FlatButton(
                //為什麼要設定左右padding,因為如果不設定,那麼會擠壓文字空間
                padding: EdgeInsets.symmetric(horizontal: 8),
                //文字顔色
                textColor: Colours.dark_button_text,
                //按鈕顔色
                color: Colours.dark_app_main,
                //畫圓角
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(4),
                ),
                //如果使用FlatButton,必須初始化onPressed這個方法
                onPressed: () {
                  widget.onPressed(_controller.text);
                },
                child: Text(
                  '搜尋',
                  style: TextStyle(fontSize: 14),
                ),
                materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
              ),
            )
           

繼續閱讀