美文网首页
flutter 中 TextButton、OutlinedBut

flutter 中 TextButton、OutlinedBut

作者: 壹点微尘 | 来源:发表于2021-02-01 15:18 被阅读0次

    设置以下属性即可:

    style: ButtonStyle(
              tapTargetSize: MaterialTapTargetSize.shrinkWrap,
              minimumSize: MaterialStateProperty.all(Size(0, 0)),
              padding: MaterialStateProperty.all(EdgeInsets.zero),
     ),
    
    去除内置padding

    完整代码:

                  Text(
                    '*****Flutter 1.22版本新增的按钮*****',
                    style: TextStyle(color: Colors.redAccent),
                  ),
                  SizedBox(height: 20),
                  Container(
                    color: Colors.orange,
                    child: TextButton(
                      onPressed: () {},
                      child: Text('TextButton'),
                      style: ButtonStyle(
                        tapTargetSize: MaterialTapTargetSize.shrinkWrap, // 设置点击区域尺寸跟随内容大小
                        minimumSize: MaterialStateProperty.all(Size(0, 0)),
                        padding: MaterialStateProperty.all(EdgeInsets.zero),
                      ),
                    ),
                  ),
                  SizedBox(height: 20),
                  Container(
                    color: Colors.blue,
                    child: OutlinedButton(
                      child: Text('OutlinedButton'),
                      onPressed: () {},
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(Colors.redAccent),
                        minimumSize: MaterialStateProperty.all(Size(0, 0)),
                        padding: MaterialStateProperty.all(EdgeInsets.zero),
                      ),
                    ),
                  ),
                  SizedBox(height: 20),
                  Container(
                    color: Colors.pinkAccent,
                    child: ElevatedButton(
                      child: Text('ElevatedButton'),
                      onPressed: () {},
                      style: ButtonStyle(
                        minimumSize: MaterialStateProperty.all(Size(0, 0)),
                        padding: MaterialStateProperty.all(EdgeInsets.zero),
                      ),
                    ),
                  ),
    

    相关文章

      网友评论

          本文标题:flutter 中 TextButton、OutlinedBut

          本文链接:https://www.haomeiwen.com/subject/rtojtltx.html