flutter - 在颤动中的按钮内使用函数的行为不符合预期
问题描述
我为按钮创建了一个类来重新设计它并在我的所有应用程序中使用它
const PrimaryButton({
Key key,
@required this.text,
@required this.paddingH,
this.press,
}) : super(key: key);
final String text;
final VoidCallback press;
final double paddingH;
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: press,
style: ElevatedButton.styleFrom(
primary: AppTheme.hexColor,
padding: EdgeInsets.symmetric(horizontal: paddingH),
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
),
child: Text(
text,
style: const TextStyle(
fontSize: 15, letterSpacing: 2.2, color: Colors.white),
),
);
}
}
我试图将类型从 voidCallback 更改为 Function 或 void 但它不起作用。
问题出在我的代码中的示例:
PrimaryButton(
text: "SAVE",
press: submitPassword,
paddingH: 30,
),
我想在 PrimaryButton 中传递这个函数
submitPassword() {
if (newPassword.text == confirmPassword.text) {
debugPrint("if");
} else {
debugPrint("else");
BotController()
.botText("passwords do not mach\n write them again please");
}
}
但它没有用,它总是给我 debugPrint("if");
我认为这是调用该函数的问题,但我无法弄清楚。
我看到了这个答案,但对我没有帮助 https://stackoverflow.com/a/50361572/13470875
解决方案是什么?为什么会这样?谢谢
解决方案
推荐阅读
- excel - Linking two different Excel tables and auto-populate one when populate another
- customization - Acumatica - 如何更改编辑按钮打开的页面(铅笔)
- facebook - FB 故事分享显示空白而不是图像,但提要通过 FB 分享显示图像
- python - 熊猫数据框中的数字已更改
- python - 芹菜任务和mysql
- python - 如何在 tkinter Python 中调整按钮中的图像
- javascript - mongoDB按路径未知的嵌套文档分组
- reactjs - 单击第二个按钮后出现的反应元素
- multithreading - 如何从 rust 中的多个线程传播错误?
- python - Python Pandas - 突出显示数据框中的单元格