function - 按下按钮时如何返回值?
问题描述
编辑:如果按下按钮,如何在我的课堂之外找到?
我尝试在 WaitForvalidation() 中使用带有 @override 的名为 isPressed 的方法,但是当我单击按钮时它总是返回“false”。这就像一个物体在推动之后被重新制作。
我的屏幕类:
class MyScreen extends StatelessWidget {
CustomRaisedButton valButton = new CustomRaisedButton();
@override
Widget build (BuildContext context) {
WaitForvalidation();
return Container(
child: valButton.build(context), // <--- Not sure that's legal...
);
}
@override
WaitForvalidation() {
// <---- HERE, I Want to know if the button was pressed !
if(valButton.isPressed())
print("Button Pressed");
}
}
我的按钮类:
class CustomRaisedButton extends StatelessWidget {
bool _active = false;
CustomRaisedButton();
bool isPressed() {
return _active
}
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.only(bottom: 10),
child: RaisedButton(
onPressed: () {
_active = true;
},
child: Text(
"Button",
),
),
);
}
}
谢谢 !
解决方案
推荐阅读
- python - 使用 pandas 中的类别重新采样,保留非数字列
- drop-down-menu - 在不同的下拉列表中选择选项时,如何取消选择下拉列表的所有选定选项?
- java - IP 作为 Linux 数组元素抛出 UnknownHostException 但作为常量起作用
- ios - IOS 上 Flutter 应用启动期间 OpenGL 渲染崩溃
- python - 如何正确运行查询 Flask-SQLAlchemy 数据库的连续测试?
- c# - 从 .net 核心中的外部应用程序控制通用主机
- javascript - 如何在 Rails 中使用中间件通过 JWT 获取 current_user_id?
- java - 如何在 beanshell 中的 java 中构造 JSON 的多个对象和数组并查看输出
- asp.net - 未保存自定义联系人方面
- php - 从没有页面刷新的操作