0

EDIT: how to find out outside of my class if the button has been pressed?

I tried with a method named isPressed with an @override in WaitForvalidation() but it return always "false" when I click on the button. It's like an object is remake just after the push.

My Screen Class :

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");
  }

}

My Button Class :

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

      ),
    );
  }
}

Thank you !

Yann
  • 21
  • 1
  • 3
  • honestly? your code does not make sense, how do you want to trigger a click when there is no button there? – Billy Apr 01 '20 at 10:55
  • I make an object from CustomRaisedButton, then i make it from .build(). What do you mean? – Yann Apr 01 '20 at 12:04
  • What you are trying to achieve? can you elaborate please? – Muhammad Noman Apr 01 '20 at 12:33
  • I have a function WaitForvalidation() to launch when the object button 'valButton' is Pressed. I'm looking for know how to do. I guess this solution is good but the object constructor seems recreated... I don't know why... – Yann Apr 01 '20 at 12:49
  • you mean that you want to know if the value of _active from another widgets? If so you should read about stateManagement especially Global State management.. Take a look at this https://flutter.dev/docs/development/data-and-backend/state-mgmt/simple – Samir N Ahmad Apr 02 '20 at 16:56

0 Answers0