【发布时间】:2020-07-21 18:32:51
【问题描述】:
好的,我在 dart/flutter 中只有几页,在第三页我想将数据添加到列表视图女巫在第一页? 我有这样的模型类:
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;
}
}
让我们在第三类/页面中说我有一些数据要通过按钮单击传递: 因此,当我单击按钮时,我需要根据模型填充列表视图...
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),
)
),
),
),
在 listView 页面上我有:
...
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('')
),
),
)
],
),
);
}
【问题讨论】:
标签: flutter listview navigation