Skip to content

Commit

Permalink
Merge pull request #47 from vinsalmont/WeekdayFormat
Browse files Browse the repository at this point in the history
Ability to choose the weekday format on the constructor
  • Loading branch information
hyochan authored Jan 12, 2019
2 parents 4295c65 + eecf93d commit c92426d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ For help getting started with Flutter, view our online
| maxSelectedDate | `DateTime` | |
| inactiveDaysTextStyle | `TextStyle` | |
| inactiveWeekendTextStyle | `TextStyle` | |
| weekDayFormat | `WeekdayFormat` | `short` |

## Install
Add ```flutter_calendar_carousel``` as a dependency in pubspec.yaml
Expand Down
42 changes: 39 additions & 3 deletions lib/flutter_calendar_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class CalendarCarousel extends StatefulWidget {
final TextStyle inactiveWeekendTextStyle;
final bool headerTitleTouchable;
final Function onHeaderTitlePressed;
final WeekdayFormat weekDayFormat;

CalendarCarousel({
this.viewportFraction = 1.0,
Expand Down Expand Up @@ -162,13 +163,23 @@ class CalendarCarousel extends StatefulWidget {
this.inactiveDaysTextStyle,
this.inactiveWeekendTextStyle,
this.headerTitleTouchable = false,
this.onHeaderTitlePressed
this.onHeaderTitlePressed,
this.weekDayFormat = WeekdayFormat.short
});

@override
_CalendarState createState() => _CalendarState();
}

enum WeekdayFormat {
weekdays,
standalone,
short,
standaloneShort,
narrow,
standaloneNarrow,
}

class _CalendarState extends State<CalendarCarousel> {
PageController _controller;
List<DateTime> _dates = List(3);
Expand Down Expand Up @@ -456,7 +467,7 @@ class _CalendarState extends State<CalendarCarousel> {
isToday
? widget.todayTextStyle
: isSelectable
? widget.inactiveWeekendTextStyle
? widget.daysTextStyle
: widget.inactiveDaysTextStyle,
maxLines: 1,
),
Expand Down Expand Up @@ -814,7 +825,32 @@ class _CalendarState extends State<CalendarCarousel> {
List<Widget> list = [];
/// because of number of days in a week is 7, so it would be easier to count it til 7.
for (var i = firstDayOfWeek, count = 0; count < 7; i = (i + 1) % 7, count++) {
String weekDay = _localeDate.dateSymbols.SHORTWEEKDAYS[i];
String weekDay;

switch (widget.weekDayFormat) {
case WeekdayFormat.weekdays:
weekDay = _localeDate.dateSymbols.WEEKDAYS[i];
break;
case WeekdayFormat.standalone:
weekDay = _localeDate.dateSymbols.STANDALONEWEEKDAYS[i];
break;
case WeekdayFormat.short:
weekDay = _localeDate.dateSymbols.SHORTWEEKDAYS[i];
break;
case WeekdayFormat.standaloneShort:
weekDay = _localeDate.dateSymbols.STANDALONESHORTWEEKDAYS[i];
break;
case WeekdayFormat.narrow:
weekDay = _localeDate.dateSymbols.NARROWWEEKDAYS[i];
break;
case WeekdayFormat.standaloneNarrow:
weekDay = _localeDate.dateSymbols.STANDALONENARROWWEEKDAYS[i];
break;
default:
weekDay = _localeDate.dateSymbols.STANDALONEWEEKDAYS[i];
break;
}

list.add(
Expanded(
child: Container(
Expand Down

0 comments on commit c92426d

Please sign in to comment.