title: How to dynamically insert and remove widgets based on demand in flutter?
body: <p>The question is common. However, I tried to simulate the event by adding a Container to the Column on tapping a button. But, the container is not added to the Column or not getting rendered on the screen.
  In addition to that, the setState method shows a warning that it isn't referenced.</p>
  
  <p>here is the code</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:focus7/Configurations/size_config.dart';
  
  class Demo2 extends StatefulWidget {
    @override
    _Demo2State createState() =&gt; _Demo2State();
  }
  
  class _Demo2State extends State&lt;Demo2&gt; {
    List&lt;Widget&gt; containersList = [
      Container(
        color: Colors.amberAccent,
        height: 100,
        width: 200,
      ),
      Container(
        color: Colors.red,
        height: 100,
        width: 200,
      ),
      Container(
        color: Colors.brown,
        height: 100,
        width: 200,
      ),
      Container(
        color: Colors.green,
        height: 100,
        width: 200,
      ),
    ];
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          body: SafeArea(
        child: Column(children: &lt;Widget&gt;[
          ...containersList,
          RaisedButton(
            onPressed: () {
              setState() =&gt; containersList.add(Container(
                    color: Colors.lightBlue,
                    height: 100,
                    width: 200,
                  ));
            },
            child: Text("click"),
          )
        ]),
      ));
    }
  }
  </code></pre>
  
  <p>here is the output:</p>
  
  <p><a href="https://i.stack.imgur.com/XYpZI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XYpZI.png" alt="enter image description here"></a></p>