设置以下属性即可:
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),
),
),
),
网友评论