编辑:如何在班级外面找出是否已按下按钮?
我尝试了一个名为isPressed的方法,并在WaitForvalidation()中使用了@override,但是当我单击按钮时,它始终返回“ 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",
),
),
);
}
}
谢谢!