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.
here is the code
import 'package:flutter/material.dart';
import 'package:focus7/Configurations/size_config.dart';
class Demo2 extends StatefulWidget {
@override
_Demo2State createState() => _Demo2State();
}
class _Demo2State extends State<Demo2> {
List<Widget> 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: <Widget>[
...containersList,
RaisedButton(
onPressed: () {
setState() => containersList.add(Container(
color: Colors.lightBlue,
height: 100,
width: 200,
));
},
child: Text("click"),
)
]),
));
}
}
here is the output:
