Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```

Expand Down
17 changes: 14 additions & 3 deletions lib/date_picker_widget.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@


import 'package:date_picker_timeline/date_widget.dart';
import 'package:date_picker_timeline/extra/color.dart';
import 'package:date_picker_timeline/extra/style.dart';
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
Expand Down Expand Up @@ -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<DateTimeType> dateSequence;

/// Shape of selected date
final BoxShape selectedDateShape;

DatePicker(
this.startDate, {
Key? key,
Expand All @@ -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.");
Expand Down Expand Up @@ -206,6 +215,8 @@ class _DatePickerState extends State<DatePicker> {
_currentDate = selectedDate;
});
},
dateSequence: widget.dateSequence,
shape: widget.selectedDateShape,
);
},
),
Expand Down
36 changes: 25 additions & 11 deletions lib/date_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// Author: Vivek Kaushik <me@vivekkasuhik.com>
/// 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';
Expand All @@ -16,13 +16,17 @@ class DateWidget extends StatelessWidget {
final Color selectionColor;
final DateSelectionCallback? onDateSelected;
final String? locale;
final BoxShape shape;
final List<DateTimeType> dateSequence;

DateWidget({
required this.date,
required this.monthTextStyle,
required this.dayTextStyle,
required this.dateTextStyle,
required this.selectionColor,
required this.dateSequence,
required this.shape,
this.width,
this.onDateSelected,
this.locale,
Expand All @@ -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: <Widget>[
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])),
),
),
),
Expand All @@ -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);
}
}
}
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down