Skip to content

Commit

Permalink
fixed colors issue & updated README file
Browse files Browse the repository at this point in the history
  • Loading branch information
El-Mazouzi committed Mar 15, 2023
1 parent 2f38688 commit f82db50
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 104 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ Updated the Readme.md file
## 1.0.7

Updated the flutter sdk to 3.7.6

## 1.0.8

Added primaryColor and backgroundColor

## 1.0.9

updated package score

## 1.0.10

Updated the Readme.md file, and added more documentation
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<p align="center"><img src="https://raw.githubusercontent.com/El-Mazouzi/custom_date_range_picker/master/screenshot.jpg" width="320" height="650"/></p>

To call the CustomDateRangePicker component, you need to pass the following props:
## Usage

```dart
...
Expand All @@ -13,10 +13,12 @@ To call the CustomDateRangePicker component, you need to pass the following prop
showCustomDateRangePicker(
context,
dismissible: true,
minimumDate: DateTime.now(),
minimumDate: DateTime.now().subtract(const Duration(days: 30)),
maximumDate: DateTime.now().add(const Duration(days: 30)),
endDate: endDate,
startDate: startDate,
backgroundColor: Colors.white,
primaryColor: Colors.green,
onApplyClick: (start, end) {
setState(() {
endDate = end;
Expand All @@ -36,6 +38,30 @@ To call the CustomDateRangePicker component, you need to pass the following prop
),
```

# Function: showCustomDateRangePicker

This function displays a custom date range picker dialog box.

## Parameters

- `context` (required): The context in which to show the dialog.
- `dismissible` (required): A boolean value indicating whether the dialog can be dismissed by tapping outside of it.
- `minimumDate` (required): A `DateTime` object representing the minimum allowable date that can be selected in the date range picker.
- `maximumDate` (required): A `DateTime` object representing the maximum allowable date that can be selected in the date range picker.
- `startDate` (optional): A nullable `DateTime` object representing the initial start date of the date range selection.
- `endDate` (optional): A nullable `DateTime` object representing the initial end date of the date range selection.
- `onApplyClick` (required): A function that takes two `DateTime` parameters representing the selected start and end dates, respectively, and is called when the user taps the "Apply" button.
- `onCancelClick` (required): A function that is called when the user taps the "Cancel" button.
- `backgroundColor` (required): The background color of the dialog.
- `primaryColor` (required): The primary color of the dialog.
- `fontFamily` (optional): The font family to use for the text in the dialog.

## Usage

Inside the function, a `FocusNode` is requested to take focus away from any input field that might be in focus. A `showDialog` function is then called to show the `CustomDateRangePicker` dialog box. The `CustomDateRangePicker` widget is built with the parameters passed to `showCustomDateRangePicker`, and then passed as the `builder` parameter of the `showDialog` function.

When the user interacts with the `CustomDateRangePicker` dialog box, the `onApplyClick` and `onCancelClick` functions are called accordingly.

Many Thanks to the creator of this Repo https://github.com/mitesh77/Best-Flutter-UI-Templates

## Getting Started
Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class _MyHomePageState extends State<MyHomePage> {
maximumDate: DateTime.now().add(const Duration(days: 30)),
endDate: endDate,
startDate: startDate,
backgroundColor: Colors.white,
primaryColor: Colors.green,
onApplyClick: (start, end) {
setState(() {
endDate = end;
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.7"
version: "1.0.10"
fake_async:
dependency: transitive
description:
Expand Down
30 changes: 20 additions & 10 deletions lib/custom_calendar.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';

/// user for DateTime formatting
import 'package:intl/intl.dart';

/// `const CustomCalendar({
Expand All @@ -8,16 +10,25 @@ import 'package:intl/intl.dart';
/// this.startEndDateChange,
/// this.minimumDate,
/// this.maximumDate,
/// required this.primaryColor,
/// })`
class CustomCalendar extends StatefulWidget {
/// The minimum date that can be selected on the calendar
final DateTime? minimumDate;

/// The maximum date that can be selected on the calendar
final DateTime? maximumDate;

/// The initial start date to be shown on the calendar
final DateTime? initialStartDate;

/// The initial end date to be shown on the calendar
final DateTime? initialEndDate;

/// The primary color to be used in the calendar's color scheme
final Color primaryColor;

/// A function to be called when the selected date range changes
final Function(DateTime, DateTime)? startEndDateChange;

const CustomCalendar({
Expand All @@ -27,6 +38,7 @@ class CustomCalendar extends StatefulWidget {
this.startEndDateChange,
this.minimumDate,
this.maximumDate,
required this.primaryColor,
}) : super(key: key);

@override
Expand Down Expand Up @@ -95,7 +107,7 @@ class CustomCalendarState extends State<CustomCalendar> {
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(24.0)),
border: Border.all(
color: Theme.of(context).dividerColor,
color: Colors.grey.shade300,
),
),
child: Material(
Expand Down Expand Up @@ -125,7 +137,7 @@ class CustomCalendarState extends State<CustomCalendar> {
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 20,
color: Theme.of(context).textTheme.displayLarge!.color,
color: Colors.grey.shade700,
),
),
),
Expand All @@ -138,7 +150,7 @@ class CustomCalendarState extends State<CustomCalendar> {
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(24.0)),
border: Border.all(
color: Theme.of(context).dividerColor,
color: Colors.grey.shade300,
),
),
child: Material(
Expand Down Expand Up @@ -191,7 +203,7 @@ class CustomCalendarState extends State<CustomCalendar> {
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Theme.of(context).primaryColor),
color: widget.primaryColor),
),
),
),
Expand Down Expand Up @@ -228,9 +240,7 @@ class CustomCalendarState extends State<CustomCalendar> {
color: startDate != null && endDate != null
? getIsItStartAndEndDate(date) ||
getIsInRange(date)
? Theme.of(context)
.primaryColor
.withOpacity(0.4)
? widget.primaryColor.withOpacity(0.4)
: Colors.transparent
: Colors.transparent,
borderRadius: BorderRadius.only(
Expand Down Expand Up @@ -299,7 +309,7 @@ class CustomCalendarState extends State<CustomCalendar> {
child: Container(
decoration: BoxDecoration(
color: getIsItStartAndEndDate(date)
? Theme.of(context).primaryColor
? widget.primaryColor
: Colors.transparent,
borderRadius:
const BorderRadius.all(Radius.circular(32.0)),
Expand All @@ -325,7 +335,7 @@ class CustomCalendarState extends State<CustomCalendar> {
color: getIsItStartAndEndDate(date)
? Colors.white
: currentMonthDate.month == date.month
? Colors.black
? widget.primaryColor
: Colors.grey.withOpacity(0.6),
fontSize:
MediaQuery.of(context).size.width > 360
Expand Down Expand Up @@ -353,7 +363,7 @@ class CustomCalendarState extends State<CustomCalendar> {
DateTime.now().year == date.year
? getIsInRange(date)
? Colors.white
: Theme.of(context).primaryColor
: widget.primaryColor
: Colors.transparent,
shape: BoxShape.circle),
),
Expand Down
Loading

0 comments on commit f82db50

Please sign in to comment.