I'm attempting to learn Flutter and would like to update the Opacity of the button on clicking it. However, there is no setState() for the Opacity widget that the button is wrapped in. Any suggestions?
Widget build(BuildContext context){
  return new Opacity(opacity: _pressed ? 1.0 : 0.0,
     child: FloatingActionButton(
       backgroundColor: Colors.blueAccent[300],
       child: Text(_entry),
       onPressed: (){
           _pressed = !_pressed;
         }),
  );
 }
The button should become "invisible" on click, and clicking again (where the button is) should make it become "visible" i.e. setting the opacity to 0 and then to 1.
Currently the button is appearing, but will not change state.
Any help is greatly appreciated, I've been looking for answers for an hour and a half now and can't find anything specific to this case :(
You should use a Visibility widget which will do the job you want (to show the floating action button or hiding it completely), but the most important part is to use the setState() function which will update the content of your screen when one of the parameter's value changes:
 Visibility(
   visible: _pressed,
   child: FloatingActionButton(
   backgroundColor: Colors.blueAccent[300],
   child: Text(_entry),
   onPressed: (){
       setState(){
         _pressed = !_pressed;
       }
    }
  ),
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With