禁用点击/单击时的评估按钮动画



点击时如何禁用评估按钮的动画。

我用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)))),

当你使用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;
},
),
),
)

相关内容

  • 没有找到相关文章

最新更新