Coder
Coder

Reputation: 658

How do I add another textbox when the user presses a button in flutter?

I have a program in which the user should be able to press a button and then the program should be able to generate a new textbox. How can I do this?

Upvotes: 1

Views: 2148

Answers (1)

Sher Ali
Sher Ali

Reputation: 5793

List<Widget>list = new List();
@override
Widget build(BuildContext context) {
return new Scaffold(
  body: new Container(
    padding: EdgeInsets.all(20.0),
    child: new ListView.builder(itemBuilder: (context, index){
    Widget widget = list.elementAt(index);
    return widget;
  }, itemCount: list.length,),),
  floatingActionButton: new FloatingActionButton(onPressed: (){
    list.add(new TextField(decoration: InputDecoration(hintText: 'Hint ${list.length+1}'),));
    setState(() {});
  }, child: new Icon(Icons.add),),
);
}

Upvotes: 3

Related Questions