Reputation: 313
I cannot distinguish two different situations by the method in the example. How can I handle loading and completion situations?
//async method
void list() {
databaseHelper.list().then((records) {
setState(() {
_recordList = records;
});
});
}
_recordList.length > 0
? ListView.builder(
itemCount: _recordList.length,
itemBuilder: (context, index) {
return {....}
})
: Center(
child: Text("No Record"),
),
I want to show CircularProgressIndicator () until the list is loaded, but if the list is empty, I want to show "No Record".
What is the way to do without using futurebuilder?
Upvotes: 0
Views: 374
Reputation: 1266
you can handle it with value null or 0
void list() {
_recordList = null;
databaseHelper.list().then((records) {
setState(() {
_recordList = records;
});
});
}
but the void list, must return a new List() when they found no records..
_recordList == null ? new new CircularProgressIndicator() :
_recordList.length > 0
? ListView.builder(
itemCount: _recordList.length,
itemBuilder: (context, index) {
return {....}
})
: Center(
child: Text("No Record"),
),
Upvotes: 1