- 当为TextButton等button添加颜色时,使用ButtonStyle为其添加颜色
-
ElevatedButton( style: ButtonStyle( backgroundColor: Color.fromRGBO(69, 123, 238, 1), padding: :EdgeInsets.only(top: 20,bottom: 20), ) child: const Text("hhh"), onPressed: () {}, )
报错,
-
改正:
-
MaterialStateProperty.all() 方法是设置点击事件所有状态下的样式。
MaterialStateProperty.resolveWith() 可拦截分别设置不同状态下的样式。
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(const Color.fromRGBO(69, 123, 238, 1)),
padding: MaterialStateProperty.all(EdgeInsets.only(top: 20,bottom: 20),)
),
child: const Text("修改手机号"),
onPressed: () {},
)