flutter 中 TextButton、OutlinedBut

2021-02-01  本文已影响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),
                  ),
                ),
              ),
上一篇 下一篇

猜你喜欢

热点阅读