'child image in visiblity widget flutter

i aim to display an image if my variable bool is true else i don't diplay it for that i used the widget visiblity . but it does not work how can fix it ?

Visibility(
            visible: widget.isThereIcon,
            child: const Padding(
              padding: EdgeInsets.only(left: 8.0),
              child: Image.asset(
                'images/OK.png',
                height: MediaQuery.of(context).size.width * .27,
                width: MediaQuery.of(context).size.width * .27,
              ),
            ),
          ),


Solution 1:[1]

is it stateless or statefull ? show how do you change state of visibility? probably you forgot about setState

setState((){
      widget.isThereIcon = true;
});

or

setState((){
      widget.isThereIcon = false;
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paweł