I'm trying to display an message, but unfortunately I think I'll need to change my method.
So I've resumed some code
child: FutureBuilder<List<Product>>(
future: products,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator(),
);
}
final products = snapshot.data!;
return Padding(
padding: const EdgeInsets.all(10.0),
child: ListView.builder(
itemCount: products.length, // currently has 400 items
itemBuilder: (context, index) {
if (difference == 0) {
return cardUI(
...
);
} else {
return Text('Nothing to display!');
}
}));
})),
How can I manage to return the message only one time? Do I need to change all the code? Since it's displaying almost 250 times 'Nothing to display'
Edit: This is what I'm using to calculate the difference!
DateTime productExpire = DateTime.parse(products[index].date);
final productDate = productExpire;
final today = DateTime.now();
final difference = calcDays(
today, productDate);