flutter TextButton

2021-07-20  本文已影响0人  那一只大象

1.overlayColor: 按钮按下时水波纹颜色

2.backgroundColor: 按钮背景色 

3.foregroundColor: 按钮字体颜色

4.设置不同状态 按钮字体颜色:

foregroundColor: MaterialStateProperty.resolveWith((states)

{

    if (states.contains(MaterialState.focused)) {

        return Colors.white;

    } else if (states.contains(MaterialState.pressed)) {

        //对应 faltbutton highlightcolor

        return Colors.red;

    }

}),

5. 设置button style 方式一:

TextButton(

                              onPressed: () => _dismissDialog(context),

                              child: Text("取消",

                                  style: TextStyle(

                                      color: Colors.black12,

                                      fontSize: screenUtil.setSp(17))),

                              style: ButtonStyle(

                              overlayColor: MaterialStateProperty.all<Color>(Colors.transparent),//splashColor

                                padding: MaterialStateProperty.all<EdgeInsetsGeometry>(EdgeInsets.all(0)),

                                backgroundColor: MaterialStateProperty.all<Color>(Color(0xFFFFC800)),

                                shape: MaterialStateProperty.all(RoundedRectangleBorder(

                                  borderRadius: BorderRadius.circular(24.0))),

                                elevation: MaterialStateProperty.all<double>(0),

                              )

                          )),

6. 设置button style 方式二:

TextButton(

          style: TextButton.styleFrom(

            backgroundColor: Color(0xFFFFC800),

            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24.0)),

            textStyle:

              TextStyle(

                color: Color(0xFF333333),

              ),

          )

上一篇下一篇

猜你喜欢

热点阅读