futureDate method
Generates a random future date from today, up to a maximum number of days.
- Defaults to a random date within the next 5 years (1825 days).
- The
days
parameter allows customization of the range.
Example:
final random = Random();
print(random.futureDate()); // Outputs: A random future date within the next 5 years
print(random.futureDate(60)); // Outputs: A random future date within the next 60 days
Implementation
DateTime futureDate([int days = 5 * 365]) {
final int randomDays = nextInt(days);
final DateTime randomDate = DateTime.now()
.add(Duration(days: randomDays, seconds: nextInt(60 * 60 * 24)));
return randomDate;
}