如何在点击时禁用评估按钮的动画。
我用 ElevatedButton.styleFrom
尝试过,但我找不到它的属性:
style: ElevatedButton.styleFrom(
primary: const Color(0xFF232441),
padding: EdgeInsets.symmetric(vertical: 15),
onPrimary: AppColors.PrimaryTextColor,
shape: RoundedRectangleBorder(
side: isSelected
? BorderSide(color: Colors.white, width: 3)
: BorderSide(color: AppColors.DayButtonColor, width: 0),
borderRadius: BorderRadius.circular(10.0)))),
答案 0 :(得分:0)
当您使用 ElevatedButton.styleFrom 方法时,它是一个工厂方法,并使用简单的输入构造 ButtonStyle,但自定义程度低,您可以从头开始创建 ButtonStyle,让您可以高级访问来自定义按钮或简单您可以在由 ElevatedButton.styleFrom 方法构造的按钮样式对象上使用副本的方式,这里是当 isSelected 为 true 时按钮高程不会动画的代码
ElevatedButton(
child: Text("Click"),
onPressed: () => print("is pressing"),
style: ElevatedButton.styleFrom(
primary: const Color(0xFF232441),
padding: EdgeInsets.symmetric(vertical: 15),
onPrimary: Colors.pink,
shape: RoundedRectangleBorder(
side: isSelected
? BorderSide(color: Colors.white, width: 3)
: BorderSide(color: Colors.green, width: 0),
borderRadius: BorderRadius.circular(10.0),
),
).copyWith(
elevation: MaterialStateProperty.resolveWith(
(states) {
double defaultElevation=3;
if (states.contains(MaterialState.disabled)) return 0;
else if (states.contains(MaterialState.hovered)) return 2;
else if (states.contains(MaterialState.focused)) return 2;
else if (states.contains(MaterialState.pressed)) {
if (isSelected)
return defaultElevation;
else
return 6;
}
return defaultElevation;
},
),
),
)