diff --git a/README.md b/README.md index d7049d1..ac4244c 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ DatePicker( this.daysCount, this.onDateChange, this.locale = "en_US", + this.dateSequence = const [TimeType.Month, TimeType.Date, TimeType.WeekDay], + this.selectedDateShape = BoxShape.rectangle, }) : super(key: key); ``` diff --git a/lib/date_picker_widget.dart b/lib/date_picker_widget.dart index 14ca445..3be1dd4 100644 --- a/lib/date_picker_widget.dart +++ b/lib/date_picker_widget.dart @@ -1,5 +1,3 @@ - - import 'package:date_picker_timeline/date_widget.dart'; import 'package:date_picker_timeline/extra/color.dart'; import 'package:date_picker_timeline/extra/style.dart'; @@ -7,6 +5,8 @@ import 'package:date_picker_timeline/gestures/tap.dart'; import 'package:flutter/material.dart'; import 'package:intl/date_symbol_data_local.dart'; +enum DateTimeType { Month, Date, WeekDay } + class DatePicker extends StatefulWidget { /// Start Date in case user wants to show past dates /// If not provided calendar will start from the initialSelectedDate @@ -60,6 +60,12 @@ class DatePicker extends StatefulWidget { /// Locale for the calendar default: en_us final String locale; + /// Sequence of Date shown to the user - from top to bottom + final List dateSequence; + + /// Shape of selected date + final BoxShape selectedDateShape; + DatePicker( this.startDate, { Key? key, @@ -78,7 +84,10 @@ class DatePicker extends StatefulWidget { this.daysCount = 500, this.onDateChange, this.locale = "en_US", - }) : assert( + this.dateSequence = const [DateTimeType.Month, DateTimeType.Date, DateTimeType.WeekDay], + this.selectedDateShape = BoxShape.rectangle, + }) : assert(dateSequence.isNotEmpty, "Date sequence can't be empty!"), + assert( activeDates == null || inactiveDates == null, "Can't " "provide both activated and deactivated dates List at the same time."); @@ -206,6 +215,8 @@ class _DatePickerState extends State { _currentDate = selectedDate; }); }, + dateSequence: widget.dateSequence, + shape: widget.selectedDateShape, ); }, ), diff --git a/lib/date_widget.dart b/lib/date_widget.dart index 1eb13f4..819e4ba 100644 --- a/lib/date_widget.dart +++ b/lib/date_widget.dart @@ -4,7 +4,7 @@ /// Author: Vivek Kaushik /// github: https://github.com/iamvivekkaushik/ /// *** - +import 'package:date_picker_timeline/date_picker_timeline.dart'; import 'package:date_picker_timeline/gestures/tap.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; @@ -16,6 +16,8 @@ class DateWidget extends StatelessWidget { final Color selectionColor; final DateSelectionCallback? onDateSelected; final String? locale; + final BoxShape shape; + final List dateSequence; DateWidget({ required this.date, @@ -23,6 +25,8 @@ class DateWidget extends StatelessWidget { required this.dayTextStyle, required this.dateTextStyle, required this.selectionColor, + required this.dateSequence, + required this.shape, this.width, this.onDateSelected, this.locale, @@ -35,22 +39,17 @@ class DateWidget extends StatelessWidget { width: width, margin: EdgeInsets.all(3.0), decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(8.0)), + shape: shape, + borderRadius: shape == BoxShape.rectangle ? BorderRadius.all(Radius.circular(8.0)) : null, color: selectionColor, ), child: Padding( padding: EdgeInsets.all(8), child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + /// making the column center aligned for a fewer options + mainAxisAlignment: dateSequence.length <= 2 ? MainAxisAlignment.center : MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text(new DateFormat("MMM", locale).format(date).toUpperCase(), // Month - style: monthTextStyle), - Text(date.day.toString(), // Date - style: dateTextStyle), - Text(new DateFormat("E", locale).format(date).toUpperCase(), // WeekDay - style: dayTextStyle) - ], + children: List.generate(dateSequence.length, (index) => _dateTimeWidget(dateSequence[index])), ), ), ), @@ -63,4 +62,19 @@ class DateWidget extends StatelessWidget { }, ); } + + /// method to get the widgets for month, date and day + _dateTimeWidget(DateTimeType dateSequence) { + switch (dateSequence) { + case DateTimeType.Month: + return Text(DateFormat("MMM", locale).format(date).toUpperCase(), // Month + style: monthTextStyle); + case DateTimeType.Date: + return Text(date.day.toString(), // Date + style: dateTextStyle); + case DateTimeType.WeekDay: + return Text(DateFormat("E", locale).format(date).toUpperCase(), // WeekDay + style: dayTextStyle); + } + } } diff --git a/pubspec.lock b/pubspec.lock index a38f32a..cda6e0d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -99,7 +99,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -134,7 +134,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: