feat: add new features for the component

This commit is contained in:
Freek van de Ven 2024-05-30 14:07:13 +02:00
parent 2ad8e46e6e
commit 49b9b90656
10 changed files with 65 additions and 267 deletions

View file

@ -1,10 +0,0 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: f1875d570e39de09040c8f79aa13cc56baab8db1
channel: stable
project_type: package

View file

@ -1,3 +1,8 @@
## 4.1.0
- Fixed a bug where there would be an extra line for the week after the current month in the month_date_time_picker
- Added more customization options for the container around the date_time_picker.dart
## 4.0.1 ## 4.0.1
- Added an extra widget builder to add more customizability, for example to add 'today' and 'close' buttons. - Added an extra widget builder to add more customizability, for example to add 'today' and 'close' buttons.

3
example/.gitignore vendored
View file

@ -45,3 +45,6 @@ app.*.map.json
/android/app/debug /android/app/debug
/android/app/profile /android/app/profile
/android/app/release /android/app/release
pubspec.lock

View file

@ -1,209 +0,0 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.11.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
characters:
dependency: transitive
description:
name: characters
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
clock:
dependency: transitive
description:
name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.dev"
source: hosted
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.17.2"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
url: "https://pub.dev"
source: hosted
version: "1.0.5"
fake_async:
dependency: transitive
description:
name: fake_async
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_date_time_picker:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "4.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "2118df84ef0c3ca93f96123a616ae8540879991b8b57af2f81b76a7ada49b2a4"
url: "https://pub.dev"
source: hosted
version: "2.0.2"
flutter_localizations:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
intl:
dependency: "direct main"
description:
name: intl
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev"
source: hosted
version: "0.18.1"
lints:
dependency: transitive
description:
name: lints
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
matcher:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
vector_math:
dependency: transitive
description:
name: vector_math
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=2.0.0"

View file

@ -16,7 +16,7 @@ dependencies:
path: ../ path: ../
flutter_localizations: flutter_localizations:
sdk: flutter sdk: flutter
intl: ^0.18.0 # Add this line intl: any
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View file

@ -28,6 +28,9 @@ class DateTimePickerTheme {
this.monthViewSize = 0.6, this.monthViewSize = 0.6,
this.weekMonthTriggerSize = 0.3, this.weekMonthTriggerSize = 0.3,
this.shapeDecoration, this.shapeDecoration,
this.border,
this.boxShadows,
this.borderRadius,
this.baseTheme = const DateBoxTheme( this.baseTheme = const DateBoxTheme(
backgroundColor: Colors.white, backgroundColor: Colors.white,
textStyle: TextStyle(color: Colors.black)), textStyle: TextStyle(color: Colors.black)),
@ -121,4 +124,13 @@ class DateTimePickerTheme {
/// The padding surrounding the calendar /// The padding surrounding the calendar
final EdgeInsetsGeometry calenderPadding; final EdgeInsetsGeometry calenderPadding;
/// Border for the container where the date picker is placed in
final Border? border;
/// BorderRadius for the container where the date picker is placed in
final BorderRadiusGeometry? borderRadius;
/// BoxShadow for the container where the date picker is placed in
final List<BoxShadow>? boxShadows;
} }

View file

@ -116,13 +116,16 @@ class _DateTimePickerState extends State<DateTimePicker> {
decoration: (widget.theme.shapeDecoration == null) decoration: (widget.theme.shapeDecoration == null)
? BoxDecoration( ? BoxDecoration(
color: widget.theme.backgroundColor, color: widget.theme.backgroundColor,
borderRadius: const BorderRadius.all(Radius.circular(16)), borderRadius: widget.theme.borderRadius ??
boxShadow: [ const BorderRadius.all(Radius.circular(16)),
BoxShadow( border: widget.theme.border,
blurRadius: 5, boxShadow: widget.theme.boxShadows ??
color: Colors.black.withOpacity(0.25), [
), BoxShadow(
], blurRadius: 5,
color: Colors.black.withOpacity(0.25),
),
],
) )
: ShapeDecoration( : ShapeDecoration(
shape: widget.theme.shapeDecoration!.shape, shape: widget.theme.shapeDecoration!.shape,

View file

@ -45,8 +45,8 @@ class DatePicker extends StatelessWidget {
addedIndex = DateTime.daysPerWeek; addedIndex = DateTime.daysPerWeek;
} }
int length = DateTime(date.year, date.month).daysInMonth() + daysToSkip; int length = DateTime(date.year, date.month).daysInMonth() + daysToSkip % 7;
int daysToAdd = DateTime.daysPerWeek - length % DateTime.daysPerWeek; int daysToAdd = (DateTime.daysPerWeek - length) % DateTime.daysPerWeek;
return Column( return Column(
children: [ children: [
if (showWeekDays) ...[ if (showWeekDays) ...[
@ -66,14 +66,11 @@ class DatePicker extends StatelessWidget {
child: Padding( child: Padding(
padding: const EdgeInsets.all(2.0), padding: const EdgeInsets.all(2.0),
child: Text( child: Text(
// The first day in November 2022 is monday // The first day in November 2022 is monday
// We use it to properly show monday as the first day and sunday as the last one // We use it to properly show monday as the first day and sunday as the last one
date, date,
style: weekdayTextStyle style: weekdayTextStyle,
// .copyWith( ),
// fontStyle: FontStyle.italic,
// fontWeight: FontWeight.w200),
),
), ),
), ),
); );

View file

@ -96,38 +96,35 @@ class _OverlayDateTimeContentState extends State<OverlayDateTimeContent> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
(widget.onPreviousPageButtonChild != null) widget.onPreviousPageButtonChild?.call(
? widget.onPreviousPageButtonChild!( (widget.dateTimeConstraint.inMonthRange(previousDate))
(widget.dateTimeConstraint.inMonthRange(previousDate)) ? _goToPreviousPage
? _goToPreviousPage : null,
: null, ) ??
) IconButton(
: IconButton( onPressed:
onPressed: (widget.dateTimeConstraint.inMonthRange(previousDate))
(widget.dateTimeConstraint.inMonthRange(previousDate)) ? _goToPreviousPage
? _goToPreviousPage : null,
: null, icon: prevIcon,
icon: prevIcon, iconSize: widget.theme.paginationSize,
iconSize: widget.theme.paginationSize, ),
),
Text( Text(
monthText, monthText,
style: widget.theme.barTheme.textStyle, style: widget.theme.barTheme.textStyle,
), ),
(widget.onNextPageButtonChild != null) widget.onNextPageButtonChild?.call(
? widget.onNextPageButtonChild!( (widget.dateTimeConstraint.inMonthRange(nextDate))
(widget.dateTimeConstraint.inMonthRange(nextDate)) ? _goToNextPage
? _goToNextPage : null,
: null, ) ??
) IconButton(
: IconButton( onPressed: (widget.dateTimeConstraint.inMonthRange(nextDate))
onPressed: ? _goToNextPage
(widget.dateTimeConstraint.inMonthRange(nextDate)) : null,
? _goToNextPage icon: nextIcon,
: null, iconSize: widget.theme.paginationSize,
icon: nextIcon, ),
iconSize: widget.theme.paginationSize,
),
], ],
), ),
Container( Container(
@ -185,7 +182,7 @@ class _OverlayDateTimeContentState extends State<OverlayDateTimeContent> {
], ],
), ),
), ),
if (widget.extraWidgetBuilder != null) widget.extraWidgetBuilder!, widget.extraWidgetBuilder ?? const SizedBox.shrink(),
], ],
); );
} }

View file

@ -1,6 +1,6 @@
name: flutter_date_time_picker name: flutter_date_time_picker
description: A Flutter package for date and time picker. description: A Flutter package for date and time picker.
version: 4.0.1 version: 4.1.0
environment: environment:
sdk: ">=3.0.0 <4.0.0" sdk: ">=3.0.0 <4.0.0"