1.首先定义好OutlineButton:
OutlinedButton(onPressed: (){
print("Outline");
},
onLongPress:(){
print("长按输出按钮ssss");
},
child: Text("你好"),
// .all :在边框之类的就是指4个边都统一设置
style:ButtonStyle(backgroundColor:MaterialStateProperty.all(Colors.lightBlue),
textStyle:MaterialStateProperty.all( const TextStyle(fontSize: 20)),
foregroundColor:MaterialStateProperty.all(Colors.deepPurpleAccent),
// padding:MaterialStateProperty.all( const EdgeInsets.all(16)),
padding:MaterialStateProperty.all( const EdgeInsets.fromLTRB(16,2,3,4)),
),
)
跳转到OutlineButton源码里面去,j加入想给按钮一个paading值,查看源码没有直接找到,
通过尝试发现在ButtonStyle里面定义的,跳转到ButtonStyle里面去:
发现了padding的定义:
点击padding跳转到定义变量padding:padding是一个 MaterialStateProperty<EdgeInsetsGeometry>?
所以在调用时也要按照这个格式来调用,
MaterialStateProperty里面的all方法来调用:
EdgeInsetsGeometry是一个抽象类,需要调用里面的静态方法,或者他的子类里面的方法,经过查看没有合适的静态方法,查找子类,ctrl+alt+b 快速查找:找到一个EdgeInsets子类,点击进去:
子类有这些方法:通过实验可以选择自己想要的方法:
最终调用:
style:ButtonStyle(
padding:MaterialStateProperty.all( const EdgeInsets.fromLTRB(16,2,3,4)),
),