Is there a way to check if ListView is empty.
ListView.builder(
itemCount: _items.length,
itemBuilder: (context, index) {
return _buildFilteredItem(context, index);
},
)
I want to search through my items and if its empty show a Text widget saying no items found. _buildFilteredItem returns null if the item could not be found.
How to Check empty list using the length property in the flutter. length property always returns int number. if it is zero , an empty list.
List. isEmpty property returns true if the List is empty, or false if it is not. List. isNotEmpty property returns false if the List is empty, or true if it is not.
ListView is a very important widget in a flutter. It is used to create the list of children But when we want to create a list recursively without writing code again and again then ListView. builder is used instead of ListView. ListView. builder creates a scrollable, linear array of widgets.
Check _items
before creating ListView
return _items.isEmpty ? Center(child: Text('Empty')) : ListView.builder(
itemCount: _items.length,
itemBuilder: (context, index) {
return _buildFilteredItem(context, index);
},
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With