Sar*_*wat 4 android ios dart flutter flutter-layout
我是颤振的新手我想显示一个图像或文本,就像No Record Found我从 listView 或 listView 中删除所有项目一样是空的。在 Android 中,我用于setEmptyView()这种情况,但我不知道如何在颤振中做到这一点。目前我正在通过 ListCan有人帮我吗?
DatabaseHelper databaseHelper = DatabaseHelper();
List<TaskModel> list;
int count = 0;
TaskModel taskModel;
@override
Widget build(BuildContext context) {
if (list == null) {
list = List<TaskModel>();
updateListView();
}
return Scaffold(
appBar: AppBar(
title: Text('Task'),
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.purple,
child: Icon(Icons.add),
onPressed: () {
Navigator.push(context,
new MaterialPageRoute<void>(builder: (context) {
return new CreateTask(TaskModel('', '', '', '', '', '', ''),'Add Task');
}));
}),
body: getTasListView()
);
}
ListView getTasListView(){
return ListView.builder(
itemCount: count,
itemBuilder: (BuildContext context, int position){
return Card(
color: Colors.white,
elevation: 2.0,
child: Column(
children: <Widget>[
ListTile(
title: Text(this.list[position].task),
onLongPress: () => navigateToDetail(this.list[position],'Edit Task'),
)
],
),
);
}
);
}
}
Run Code Online (Sandbox Code Playgroud)
Ana*_*ore 13
检查长度或数组并决定返回哪个小部件。
Widget getTasListView() {
return arrList.isNotEmpty
? ListView.builder(
itemCount: arrList.length,
itemBuilder: (BuildContext context, int position) {
return Card(
color: Colors.white,
elevation: 2.0,
child: Column(
children: <Widget>[
ListTile(
title: Text(this.list[position].task),
onLongPress: () =>
navigateToDetail(this.list[position], 'Edit Task'),
)
],
),
);
})
: Center(child: Image.asset("path/image/img.png"));
}
Run Code Online (Sandbox Code Playgroud)
并使用arrList.length代替itemCount: count.
| 归档时间: |
|
| 查看次数: |
5217 次 |
| 最近记录: |