diff --git a/example/lib/widgets/week_view_widget.dart b/example/lib/widgets/week_view_widget.dart index 615f32c7..68e41025 100644 --- a/example/lib/widgets/week_view_widget.dart +++ b/example/lib/widgets/week_view_widget.dart @@ -14,9 +14,9 @@ class WeekViewWidget extends StatelessWidget { return WeekView( key: state, width: width, - showWeekends: true, + showWeekends: false, showLiveTimeLineInAllDays: true, - showThreeDaysView: true, + // showThreeDaysView: true, eventArranger: SideEventArranger(maxWidth: 30), timeLineWidth: 65, scrollPhysics: const BouncingScrollPhysics(), diff --git a/lib/src/extensions.dart b/lib/src/extensions.dart index ccaff3ce..1978b7e5 100644 --- a/lib/src/extensions.dart +++ b/lib/src/extensions.dart @@ -65,29 +65,25 @@ extension DateTimeExtensions on DateTime { // adding 1 in index. So, new formula with WeekDays is, // difference = (weekdays - (start.index + 1))%7 - // final startDay = - // DateTime(year, month, day - (weekday - start.index - 1) % 7); - // // Generate weekdays with weekends or without weekends - // final days = List.generate( - // 7, - // (index) => DateTime(startDay.year, startDay.month, startDay.day + index), - // ) - // .where( - // (date) => - // showWeekEnds || - // (date.weekday != DateTime.saturday && - // date.weekday != DateTime.sunday), - // ) - // .toList(); - - // Three days view - // final days = showThreeDays ? day : day - (weekday - start.index - 1) % 7; - // final startDay = DateTime(year, month, days); - // - // return List.generate(showThreeDays ? 3 : 7, (index) { - // return startDay.add(Duration(days: index)); - // }); - return days; + // Generate weekdays with weekends or without weekends + final newDays = []; + var daysToGenerate = showThreeDays ? 3 : 7; + var i = 0; + final startDate = DateTime(year, month, day); + + while (i < daysToGenerate) { + final nextDay = startDate.add(Duration(days: i)); + if (showWeekEnds) { + newDays.add(nextDay); + i++; + } else if (nextDay.weekday != DateTime.saturday && + nextDay.weekday != DateTime.sunday) { + newDays.add(nextDay); + i++; + } + } + + return newDays; } /// Returns the first date of week containing the current date diff --git a/lib/src/week_view/week_view.dart b/lib/src/week_view/week_view.dart index c9778b84..0f124f27 100644 --- a/lib/src/week_view/week_view.dart +++ b/lib/src/week_view/week_view.dart @@ -528,15 +528,15 @@ class WeekViewState extends State> { physics: widget.pageViewPhysics, onPageChanged: _onPageChange, itemBuilder: (_, index) { - final dates = DateTime(_minDate.year, _minDate.month, - _minDate.day + (index * DateTime.daysPerWeek)) - .datesOfWeek( - start: widget.startDay, - showWeekEnds: widget.showWeekends, - ); + // final dates = DateTime(_minDate.year, _minDate.month, + // _minDate.day + (index * DateTime.daysPerWeek)) + // .datesOfWeek( + // start: widget.startDay, + // showWeekEnds: widget.showWeekends, + // ); // TODO(Shubham): Three days view - // final dates = _getDatesOnWeek(index); + final dates = _getDatesOnWeek(index); return ValueListenableBuilder( valueListenable: _scrollConfiguration,