'How to get all dates and weekdays in current month in flutter
I want to get current months all dates and weekdays like below image
i get all dates with below code
DateTime now = DateTime.now();
late DateTime lastDayOfMonth;
lastDayOfMonth = DateTime(now.year, now.month + 1, 0);
Row(
children: List.generate(
lastDayOfMonth.day,
(index) => Padding(
padding: const EdgeInsets.only(right: 24.0),
child: Text(
"${index + 1}",
),
),
),
but i didn't get weekdays according dates
Solution 1:[1]
The lastDayOfMonth is a single date, therefore using lastDayOfMonth.weekDay gives a single day based on lastDayOfMonth. We can add duration on lastDayOfMonth and find day name.
final currentDate =
lastDayOfMonth.add(Duration(days: index + 1));
This will provide update date based on index. I am using intl package or create a map to get the day name.
A useful answer about date format.
Row(
children: List.generate(
lastDayOfMonth.day,
(index) => Padding(
padding: const EdgeInsets.only(right: 24.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"${index + 1}",
),
() {
final currentDate =
lastDayOfMonth.add(Duration(days: index + 1));
final dateName =
DateFormat('E').format(currentDate);
return Text(dateName);
}()
],
),
),
),
),
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MohammedAli |

