Flutter TextButton一些属性

Scaffold(
        appBar:AppBar(
          automaticallyImplyLeading: true,
          title:const Text('TextButton属性'),
        ),
        body: Column(
           mainAxisSize: MainAxisSize.max,
           children: [
             //const MyBody(),

             OutlinedButton(
               onPressed: null,
               child:const Text('Disabled'),
               style:ButtonStyle(textStyle:MaterialStateProperty.all(
                 const TextStyle(fontSize: 20,color:Colors.white,backgroundColor: Colors.blue,
                    decoration: TextDecoration.underline,
                 ),
               )),
             ),
             const SizedBox(height: 30,),


             TextButton(
               onPressed: (){},
               child: const Text('hello'),
               // textButtonTheme: TextButtonThemeData(
               // style: ButtonStyle(
               //   backgroundColor:
               //   MaterialStateProperty.all<Color>(Colors.transparent),
               //   overlayColor:
               //   MaterialStateProperty.all<Color>(Colors.transparent),
               // ),
               style:ButtonStyle(
                 //定义文本的样式 这里设置的颜色是不起作用的
                 textStyle: MaterialStateProperty.all(const TextStyle(fontSize: 18, color: Colors.red)),
                 //设置按钮上字体与图标的颜色
                 //foregroundColor: MaterialStateProperty.all(Colors.deepPurple),
                 //更优美的方式来设置
                 foregroundColor: MaterialStateProperty.resolveWith(
                       (states) {
                     if (states.contains(MaterialState.focused) &&
                         !states.contains(MaterialState.pressed)) {
                       //获取焦点时的颜色
                       return Colors.blue;
                     } else if (states.contains(MaterialState.pressed)) {
                       //按下时的颜色
                       return Colors.deepPurple;
                     }
                     //默认状态使用灰色
                     return Colors.grey;
                   },
                 ),
                 //背景颜色
                 backgroundColor: MaterialStateProperty.resolveWith((states) {
                   //设置按下时的背景颜色
                   if (states.contains(MaterialState.pressed)) {
                     return Colors.blue[200];
                   }
                   //默认不使用背景颜色
                   return null;
                 }),
                 //设置水波纹颜色
                 overlayColor: MaterialStateProperty.all(Colors.yellow),
                 //设置阴影  不适用于这里的TextButton
                 elevation: MaterialStateProperty.all(0),
                 //设置按钮内边距
                 padding: MaterialStateProperty.all(EdgeInsets.all(10)),
                 //设置按钮的大小
                 minimumSize: MaterialStateProperty.all(Size(200, 100)),
                 //设置边框
                 side: MaterialStateProperty.all(BorderSide(color: Colors.grey, width: 1)),
                 //外边框装饰 会覆盖 side 配置的样式
                 shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
               ),
             ),

            const SizedBox(height: 10,),


            TextButton(
               onPressed: () {},
               child:const Text('Enabled',style: TextStyle(color: Colors.white),),
             //圆角
               style:ButtonStyle(
                    //设置按钮内边距
                    padding: MaterialStateProperty.all(const EdgeInsets.fromLTRB(20, 5, 20, 5)),
                   // shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
                   //边框
                   side: MaterialStateProperty.all(const BorderSide(color: Colors.red, width: 2)),
                   //背景
                   backgroundColor:MaterialStateProperty.all(Colors.blue),
                 //设置按钮的大小
                 minimumSize: MaterialStateProperty.all(Size(200, 100)),
                 //外边框装饰 会覆盖 side 配置的样式
                 shape: MaterialStateProperty.all(const StadiumBorder()),

               ),
             ),

             const SizedBox(height: 10,),

             OutlinedButton(onPressed: (){}, child:const Text("haha"))
           ],
        ),
    );

参考:flutter新版按钮常用设置_flutter-难得一见的博客 

如有侵权:请联系删除

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值