isYesterday method
Checks if the current DateTime provided was yesterday.
This comparison ignores time components (hours, minutes, seconds).
@returns True if the date is exactly one calendar day before today.
Example:
final yesterday = DateTime.now().subtract(const Duration(days: 1));
print(yesterday.isYesterday()); // true
Implementation
bool isYesterday() {
final DateTime now = DateTime.now();
final DateTime date = DateTime(year, month, day);
final DateTime today = DateTime(now.year, now.month, now.day);
// Checks if the difference between today and the date is exactly 1 day.
return today.difference(date).inDays == 1;
}