Как вернуть значение при нажатии на кнопку? - PullRequest
0 голосов
/ 01 апреля 2020

РЕДАКТИРОВАТЬ: как узнать за пределами моего класса, была ли нажата кнопка?

Я пытался с методом с именем isPressed с @override в WaitForvalidation (), но он всегда возвращает "ложь", когда я нажмите на кнопку. Это как объект, переделанный сразу после пу sh.

Мой класс экрана:

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",
        ),

      ),
    );
  }
}

Спасибо!

...