diff --git a/README.md b/README.md index 83f473c..9e42113 100644 --- a/README.md +++ b/README.md @@ -17,41 +17,40 @@ For help getting started with Flutter, view our online [documentation](https://flutter.io/). ## Props -| props | types | defaultValues | -| :---------------------- | :-------------: | :---------------------------------------------------------------------------------------------------------------: | -| weekDays | | ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'] | -| viewPortFraction | `double` | 1.0 | -| prevDaysTextStyle | `TextStyle` | | -| daysTextStyle | `TextStyle` | | -| nextDaysTextStyle | `TextStyle` | | -| prevMonthDayBorderColor | `Color` | Colors.transparent | -| thisMonthDayBorderColor | `Color` | Colors.transparent | -| nextMonthDayBorderColor | `Color` | Colors.transparent | -| dayPadding | `double` | 2.0 | -| height | `double` | double.infinity | -| width | `double` | double.infinity | -| todayTextStyle | `TextStyle` | `fontSize: 14.0, color: Colors.white` | -| dayButtonColor | `Color` | Colors.red | -| todayBorderColor | `Color` | Colors.red | -| todayButtonColor | `Colors` | Colors.red | -| selectedDateTime | `DateTime` | | -| selectedDayTextStyle | `TextStyle` | `fontSize: 14.0, color: Colors.white` | -| selectedDayBorderColor | `Color` | Colors.green | -| selectedDayButtonColor | `Color` | Colors.green | -| daysHaveCircularBorder | `bool` | | -| onDayPressed | `Func` | | -| weekdayTextStyle | `TextStyle` | `fontSize: 14.0, color: Colors.deepOrange` | -| iconColor | `Color` | Colors.blueAccent | -| headerTextStyle | `TextStyle` | `fontSize: 20.0, color: Colors.blue` | -| headerText | `Text` | `Text('${DateFormat.yMMM().format(this._dates[1])}'`) | -| weekendTextStyle | `TextStyle` | `fontSize: 14.0, color: Colors.pinkAccent` | -| markedDates | `List { PageController _controller; List _dates = List(3); - DateTime _selectedDate = DateTime.now(); int _startWeekday = 0; int _endWeekday = 0; @@ -164,56 +160,32 @@ class _CalendarState extends State { style: widget.headerTextStyle != null ? widget.headerTextStyle : widget.defaultHeaderTextStyle, - child: widget.weekFormat - ? Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - IconButton( - onPressed: () => resetToToday(), - icon: Icon(Icons.today, color: widget.iconColor), - ), - Container( - child: widget.headerText != null - ? widget.headerText - : Text( - '${DateFormat.yMMM().format(this._dates[1])}', - ), - ), - IconButton( - onPressed: () => selectDateFromPicker(), - icon: Icon( - Icons.calendar_today, - color: widget.iconColor, - ), - ), - ], - ) - : Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - IconButton( - onPressed: () => _setDate(page: 0), - icon: Icon( - Icons.keyboard_arrow_left, - color: widget.iconColor, - ), - ), - Container( - child: widget.headerText != null - ? widget.headerText - : Text( - '${DateFormat.yMMM().format(this._dates[1])}', - ), - ), - IconButton( - onPressed: () => _setDate(page: 2), - icon: Icon( - Icons.keyboard_arrow_right, - color: widget.iconColor, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + IconButton( + onPressed: () => _setDate(page: 0), + icon: Icon( + Icons.keyboard_arrow_left, + color: widget.iconColor, + ), + ), + Container( + child: widget.headerText != null + ? widget.headerText + : Text( + '${DateFormat.yMMM().format(this._dates[1])}', ), - ), - ], + ), + IconButton( + onPressed: () => _setDate(page: 2), + icon: Icon( + Icons.keyboard_arrow_right, + color: widget.iconColor, ), + ), + ], + ), ), ), Container( @@ -225,19 +197,17 @@ class _CalendarState extends State { ), ), Expanded( - child: widget.weekFormat - ? Builder(builder: weekBuilder, key: widget.key) - : PageView.builder( - itemCount: 3, - onPageChanged: (value) { - this._setDate(page: value); - }, - controller: _controller, - itemBuilder: (context, index) { - return builder(index); - }, - pageSnapping: true, - ), + child: PageView.builder( + itemCount: 3, + onPageChanged: (value) { + this._setDate(page: value); + }, + controller: _controller, + itemBuilder: (context, index) { + return builder(index); + }, + pageSnapping: true, + ), ), ], ), @@ -417,171 +387,6 @@ class _CalendarState extends State { ); } - Widget weekBuilder(BuildContext context) { - List weekDays = getDaysInWeek(selectedDate: this._selectedDate); - - return Stack( - children: [ - Positioned( - child: Container( - width: double.infinity, - height: double.infinity, - child: GridView.count( - crossAxisCount: 7, - childAspectRatio: widget.childAspectRatio, - padding: EdgeInsets.zero, - children: List.generate(weekDays.length, - - /// last day of month + weekday - (index) { - bool isToday = weekDays[index].day == DateTime.now().day && - weekDays[index].month == DateTime.now().month && - weekDays[index].year == DateTime.now().year; - bool isSelectedDay = this._selectedDate != null && - this._selectedDate.year == weekDays[index].year && - this._selectedDate.month == weekDays[index].month && - this._selectedDate.day == weekDays[index].day; - bool isPrevMonthDay = - weekDays[index].month < this._selectedDate.month; - bool isNextMonthDay = - weekDays[index].month > this._selectedDate.month; - bool isThisMonthDay = !isPrevMonthDay && !isNextMonthDay; - - DateTime now = weekDays[index]; - TextStyle textStyle; - TextStyle defaultTextStyle; - if (isPrevMonthDay) { - textStyle = widget.prevDaysTextStyle; - defaultTextStyle = widget.defaultPrevDaysTextStyle; - } else if (isThisMonthDay) { - textStyle = isSelectedDay - ? widget.selectedDayTextStyle - : isToday ? widget.todayTextStyle : widget.daysTextStyle; - defaultTextStyle = isSelectedDay - ? widget.defaultSelectedDayTextStyle - : isToday - ? widget.defaultTodayTextStyle - : widget.defaultDaysTextStyle; - } else { - textStyle = widget.nextDaysTextStyle; - defaultTextStyle = widget.defaultNextDaysTextStyle; - } - - return Container( - margin: EdgeInsets.all(widget.dayPadding), - child: FlatButton( - color: isSelectedDay && widget.todayBorderColor != null - ? widget.selectedDayBorderColor - : isToday && widget.todayBorderColor != null - ? widget.todayButtonColor - : widget.dayButtonColor, - onPressed: () => _onDayPressed(now), - padding: EdgeInsets.all(widget.dayPadding), - shape: widget.daysHaveCircularBorder == null - ? CircleBorder() - : widget.daysHaveCircularBorder - ? CircleBorder( - side: BorderSide( - color: isPrevMonthDay - ? widget.prevMonthDayBorderColor - : isNextMonthDay - ? widget.nextMonthDayBorderColor - : isToday && - widget.todayBorderColor != - null - ? widget.todayBorderColor - : widget.thisMonthDayBorderColor, - ), - ) - : RoundedRectangleBorder( - side: BorderSide( - color: isPrevMonthDay - ? widget.prevMonthDayBorderColor - : isNextMonthDay - ? widget.nextMonthDayBorderColor - : isToday && - widget.todayBorderColor != - null - ? widget.todayBorderColor - : widget.thisMonthDayBorderColor, - ), - ), - child: Stack( - children: [ - Center( - child: DefaultTextStyle( - style: (index % 7 == 0 || index % 7 == 6) && - !isSelectedDay && - !isToday - ? widget.defaultWeekendTextStyle - : isToday - ? widget.defaultTodayTextStyle - : defaultTextStyle, - child: Text( - '${now.day}', - style: (index % 7 == 0 || index % 7 == 6) && - !isSelectedDay && - !isToday - ? widget.weekendTextStyle - : isToday ? widget.todayTextStyle : textStyle, - maxLines: 1, - ), - ), - ), - _renderMarked(now), - ], - ), - ), - ); - }), - ), - ), - ), - ], - ); - } - - List getDaysInWeek({DateTime selectedDate}) { - if (selectedDate == null) selectedDate = new DateTime.now(); - - var firstDayOfCurrentWeek = Utils.firstDayOfWeek(selectedDate); - var lastDayOfCurrentWeek = Utils.lastDayOfWeek(selectedDate); - - return Utils.daysInRange(firstDayOfCurrentWeek, lastDayOfCurrentWeek) - .toList(); - } - - void resetToToday() { - _selectedDate = new DateTime.now(); - setState(() { - this._selectedDate = _selectedDate; - }); - } - - void _onDayPressed(DateTime picked) { - if (picked == null) return; - setState(() { - this._selectedDate = picked; - }); - widget.onDayPressed(picked); - } - - Future selectDateFromPicker() async { - DateTime selected = await showDatePicker( - context: context, - initialDate: this._selectedDate ?? new DateTime.now(), - firstDate: new DateTime(1960), - lastDate: new DateTime(2050), - ); - - if (selected != null) { - setState(() { - this._selectedDate = selected; - }); - // updating selected date range based on selected week - } - } - void _setDate({ int page, }) { @@ -602,9 +407,6 @@ class _CalendarState extends State { date1, date2, ]; - this._selectedDate = widget.selectedDateTime != null - ? widget.selectedDateTime - : DateTime.now(); }); } else if (page == 1) { return; diff --git a/pubspec.lock b/pubspec.lock index c6a9fd7..b4515f0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -64,13 +64,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.14.6" - date_utils: - dependency: "direct main" - description: - name: date_utils - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.0+2" flutter: dependency: "direct main" description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index b3a5fdd..b34bf42 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,6 @@ dependencies: intl: ^0.15.7 flutter: sdk: flutter - date_utils: ^0.1.0 dev_dependencies: flutter_test: