Ok, IM have few pages in dart/flutter, on third page I want to add data to list view witch is on the first page? I have Model class like this:
class Doors_Model {
final String image;
final String name;
final String desc;
Doors_Model({this.image, this.name, this.desc});
static List<Doors_Model> allDevices() {
var listOfAllDoors = new List<Doors_Model>();
listOfAllDoors.add(
new Doors_Model(image: 'door.png', name: 'name', desc: 'description'));
return listOfAllDoors;
}
}
Lets just say in third class/page I have some data to pass with button click : So when I click the button i need to populate list view base on the model...
class AddDevices extends StatefulWidget {
@override
_AddDevicesState createState() => _AddDevicesState();
}
class _AddDevicesState extends State<AddDevices> {
@override
Widget build(BuildContext context) {
child: Material(
child: Scaffold(
floatingActionButton : FloatingActionButton(
onPressed: (){
_addDataToListView();
}, elevation: 3,child: Icon(Icons.add),
)
),
),
),
And on the listView page I have:
...
class _HomeState extends State<Home> {
final List<Doors_Model> _allDevices = Doors_Model.allDevices();
...
Widget _getList(BuildContext context, int index) {
return Card(
child: Column(
children: <Widget>[
ListTile(
leading: Image.asset(
"assets/" + _allDevices[index].image,
),
title: Text(_allDevices[index].name),
subtitle: Text(_allDevices[index].desc),
trailing: Text('')
),
),
)
],
),
);
}