I try to display dates of weeks. but based on requirement i need to skip Saturday and Sunday every time.
here is code of date list:-
ListView.builder(
itemCount: 7,
shrinkWrap: true,
itemBuilder: (context, index) => dateWidget(index),
),
here is code of dateWidget() method which is used for displaying dates:-
Widget dateWidget(int i) {
DateTime tempDate = DateTime.now().add(Duration(days: i));
return InkWell(
onTap: () {},
child: Container(
margin: const EdgeInsets.all(2),
width: 10.0,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10)),
color: AppColor.premiumBlue,
),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
labels(text: DateFormat('EE').format(tempDate).toUpperCase()),
labels(
text: tempDate.day.toString(),
color: AppColor.white,
),
],
),
),
),
);
}
I need to skip Saturday and Sunday dates. if i enter 7 so, display 7 dates and also skip Saturday and Sunday. If any date is cut then last date should also be added.
For example:-
I enter 7, means i want to display 7 date from today.
So, happen like this..
17-FRI, 18-SAT, 19-SUN, 20-MON, 21-TUE, 22-WED, 23-THU (currently happen this)
and want to skip Saturday and Sunday.
So, happen like this..
17-FRI, 20-MON, 21-TUE, 22-WED, 23-THU, 24-FRI (I want like this.)
2
Answers
You can return empty sizedBox based on weekday
New Solution
Instead of using
ListView.builder
, pass in a list of the generated widgets to aListView
as so:dateWidget
remains unchangedOld Solution (doesn’t work)
Note: this solution doesn’t work since ListView.builder
One solution (that isn’t that great, but works) is to do it like so by doing the calculations before creating the dateWidget:
And then
An alternative solution would be to do what @YeasinSheikh suggested. Instead of using a number to determine the number of weekdays we want, set a certain date you want to have
dateWidgets
to and then calculate the number of days you need and put that intoitemCount
.