reload a list view after adding elements to list view

6,646 views
Skip to first unread message

Si...@prayuta.com

unread,
Sep 11, 2017, 7:30:29 AM9/11/17
to Flutter Dev
Hi dev team,

I am trying to reload the list after adding new element to the list view but I am not able to find any example to reload.
for the list view
 
can anyone help

class chitmapping extends StatelessWidget {
addclicked(){
print('add button clicked');
items.add('j');
print(items);
}
bool _showDividers = true;
bool _reverseSort = false;
List<String> items = <String>['a', 'b', 'c', 'd', 'e','f', 'g', 'h', 'i', ];
Widget buildListTile(BuildContext context, String item) {



return new MergeSemantics(
child: new ListTile(

dense: false,
leading: new ExcludeSemantics(child: new CircleAvatar(child: new Text(item[0].toUpperCase()))) ,
title: new Text('This item represents $item.'),
subtitle: new Text('subtitle'),

),
);
}

@override
Widget build(BuildContext context) {
Iterable<Widget> listTiles = items.map((String item) => buildListTile(context, item));
if (_showDividers)
listTiles = ListTile.divideTiles(context: context, tiles: listTiles);

return new Scaffold(
appBar: new AppBar(
title: new Text('Transaction'),
backgroundColor: custom_color.appheadercolor,
),
body:
new ListView(children: <Widget>[ new Container(height: 80.0,
padding: const EdgeInsets.only(left:16.0,top: 8.0,right: 16.0),
child: new Row(

children:[
new Expanded(child:



new Container(

padding: const EdgeInsets.only(left: 8.0,right: 8.0),

child:new TextField(
decoration: new InputDecoration(hintText: 'Enter name',labelText: 'Name'),
style: new TextStyle(fontSize: 18.0,color: Colors.black),
),
),),
new RaisedButton(onPressed: addclicked,child: new Text('ADD'),color:Colors.green)
])),
new Container(child: new Column(
// padding: new EdgeInsets.symmetric(vertical: 8.0),
children: listTiles.toList(),

),),
],

)


);
}
}


Michael Thomsen

unread,
Sep 11, 2017, 7:37:39 AM9/11/17
to Si...@prayuta.com, Flutter Dev
Try using a StatefulWidget, and then update items inside setState to alert Flutter of what state was updated. This is similar to how the standard app template does with the _counter state.

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Si...@prayuta.com

unread,
Sep 14, 2017, 3:48:03 AM9/14/17
to Flutter Dev
ya it worked for me

Thank for ur solution.
Reply all
Reply to author
Forward
0 new messages