编辑:如果按下按钮,如何在我的课堂之外找到?
我尝试在 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",
),
),
);
}
}
谢谢 !