Flutter - Render new Widgets on click

后端 未结 2 886
谎友^
谎友^ 2021-02-14 02:05

The title basically says it all. A very nooby question... I have this basic code to create the initial state of my app :

class MyApp extends StatelessWidget {
           


        
2条回答
  •  庸人自扰
    2021-02-14 02:51

    Your build function is "just code", so you can build the array you pass to the column dynamically, using something like

    var children = [];
    children.add(new InputWidget());
    if (_showAnother)
      children.add(new InputWidget());
    ...
      body: new Column(
        ...
        children: children,
    ...
    

    ...where _showAnother is some sort of bool field that you set when the button is tapped.

提交回复
热议问题