title: flutter state widget dynamically change variable
body: <p>I am building a chatbot with message and button responses. How to change a variable that is defined in the widget build in-state widget? I want to show the buttons when its added dynamically and when the user clicks the button, the button container has to disappear. now, it is disappearing but the buttons for the next messages are not showing.
  buttons are mentioned as label</p>
  <pre><code>class _BodyState extends State&lt;Body&gt; {
    bool demo = true;
    @override
    void initState() {
      // TODO: implement initState
      super.initState();
      demo = true;
    }
  
    @override
    Widget build(BuildContext context) {
      return ListView.separated(
        itemBuilder: (context, i) {
          var obj = widget.messages[widget.messages.length - 1 - i];
  
          Message message = obj['message'];
          bool isUserMessage = obj['isUserMessage'] ?? false;
          List&lt;dynamic&gt; label = obj['label'];
          bool show = obj['show'];
          if (show) show1();
          return Column(
            crossAxisAlignment:
                isUserMessage ? CrossAxisAlignment.end : CrossAxisAlignment.start,
            children: [
              Row(
                mainAxisAlignment: isUserMessage
                    ? MainAxisAlignment.end
                    : MainAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: [
                  _MessageContainer(
                    message: message,
                    isUserMessage: isUserMessage,
                  ),
                ],
              ),
              if (label.length &gt; 0)
                  !demo
                      ? SizedBox(
                          width: 10,
                        )
                      : Visibility(
                          child: Container(
                              constraints: BoxConstraints(maxWidth: 250),
                              padding: EdgeInsets.only(top: 10, left: 35),
                              child: ListView.builder(
                                  itemCount: label.length,
                                  shrinkWrap: true,
                                  itemBuilder: (context, i) {
                                    return ElevatedButton(
                                      child: Text(label[i]),
                                      onPressed: () =&gt; {
                                        widget.hi!(label[i], true),
                                        setState(() {
                                          hide();
                                        })
                                      },
                                      style: ButtonStyle(
                                        shape: MaterialStateProperty.all&lt;
                                            RoundedRectangleBorder&gt;(
                                          RoundedRectangleBorder(
                                            borderRadius:
                                                BorderRadius.circular(18.0),
                                            side: BorderSide(
                                              color: Colors.black,
                                              width: 2.0,
                                            ),
                                          ),
                                        ),
                                      ),
                                    );
                                  })),
                        )
            ],
          );
        },
        separatorBuilder: (_, i) =&gt; Container(height: 10),
        itemCount: widget.messages.length,
        reverse: true,
        padding: const EdgeInsets.symmetric(
          horizontal: 10,
          vertical: 20,
        ),
      );
    }
  
    void show1() {
      demo = true;
    }
  
    void hide() {
      setState(() {
        demo = !demo;
        if (demo) {
          debugPrint(&quot;true&quot;);
        } else {
          debugPrint(&quot;False&quot;);
        }
      });
    }
  </code></pre>