flutter 去除RaisedButton、FlatButto
2021-02-01 本文已影响0人
壹点微尘
之前一直忙于开发, 也没有去读源码,这些按钮内置padding怎么也去除不掉,今儿读了下源码, so easy
按钮默认内置padding
RaisedButton(
child: Text('RaisedButton'),
onPressed: () {},
),
FlatButton(
child: Text('Button', style: TextStyle(color: Colors.white)),
color: Colors.pink,
onPressed: () {},
),
OutlineButton(
child: Text('OutlineButton'),
onPressed: () {},
),
那么怎么去除这写内置padding呢?只需要在main.dart
文件中设置buttonTheme
即可:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Study',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
buttonTheme: ButtonThemeData(
minWidth: 0,
height: 0,
padding: EdgeInsets.zero, // 可以设置为zero,
// padding: EdgeInsets.symmetric(
// // 也可以根据自己需要设置padding
// horizontal: 15,
// vertical: 8,
// ),
),
),
home: CYRoot(),
);
}
}
去除了内置padding
也可在代码中手动设置
padding
RaisedButton(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Text('RaisedButton'),
onPressed: () {},
),
手动设置padding