Compare commits

...

22 commits

Author SHA1 Message Date
Gorter-dev
91bb2399e8
Merge pull request #50 from Iconica-Development/chore/deploy
chore: ready the package for deployment to the pub server
2024-07-22 14:57:54 +02:00
Bart Ribbers
15a04c94ef chore: ready the package for deployment to the pub server 2024-07-11 19:08:50 +02:00
Bart Ribbers
50f88941e4 chore: add fvm configuration to gitignore 2024-07-11 19:07:23 +02:00
Vick Top
d18b662c9c doc: create documentation for files 2024-06-03 11:38:44 +02:00
Freek van de Ven
a193fc5563 feat: add new features for the component 2024-05-31 09:31:47 +02:00
Freek van de Ven
2ad8e46e6e
Merge pull request #44 from Iconica-Development/update-component-documentation-workflow-correct
Add component-documentation.yml correct
2024-02-14 08:07:58 +01:00
Vick Top
94f8fa6a08 feat(documentation): Create component-documentation.yml workflow file 2024-02-13 13:37:11 +01:00
Vick Top
7ab9fcd302 chore: Remove old component-documentation.yml 2024-02-13 13:37:11 +01:00
Freek van de Ven
ab93a7cb59
Merge pull request #43 from Iconica-Development/update-component-documentation-workflow
Add component-documentation.yml
2024-02-12 20:21:59 +01:00
Vick Top
5bd7ab9e79 feat(documentation): Create component-documentation.yml workflow file 2024-02-12 19:09:06 +01:00
Freek van de Ven
fdccd78798 chore: add figma links 2023-12-17 11:59:42 +01:00
Gorter-dev
31a74c1173
Merge pull request #42 from Iconica-Development/feat/add-extra-widget
feat: add extra widget builder
2023-11-16 13:28:25 +01:00
Floris Halleriet
d154c1eecb feat: add extra widget builder 2023-11-16 11:50:17 +01:00
Gorter-dev
706ecf99f9
Merge pull request #41 from Iconica-Development/feature/borderscroll
feat: Controller now has to be provided as parameter so the selected …
2023-11-07 10:10:18 +01:00
Jacques
b61b24aa40 fix: dart format 2023-11-07 09:47:27 +01:00
Jacques
b0dea5e49b fix: Unused imports 2023-11-07 09:29:57 +01:00
Jacques
5f24c04248 fix: Split the controller into a configration and controller. 2023-11-07 09:28:44 +01:00
Jacques
61e2b849fa feat: Controller now has to be provided as parameter so the selected date can be changed from outside the widget. 2023-11-06 13:57:35 +01:00
Freek van de Ven
55ec65d59e
Merge pull request #39 from Iconica-Development/feat/marked-theme
feat: add marked theme for marked dates to be like selected dates
2023-10-26 11:07:09 +02:00
FahadFahim71
13bddefd7e feat: add marked theme for marked dates to be like selected dates 2023-10-26 11:06:13 +02:00
Gorter-dev
e38f4db301
Merge pull request #37 from Iconica-Development/bugfix/date_picker_size
https://github.com/Iconica-Development/flutter_date_time_picker/issues/30
2023-10-06 11:54:34 +02:00
mike doornenbal
77a16b04ef https://github.com/Iconica-Development/flutter_date_time_picker/issues/30 2023-10-06 11:52:51 +02:00
31 changed files with 792 additions and 532 deletions

3
.fvmrc Normal file
View file

@ -0,0 +1,3 @@
{
"flutter": "3.22.2"
}

View file

@ -0,0 +1,14 @@
name: Iconica Standard Component Documentation Workflow
# Workflow Caller version: 1.0.0
on:
release:
types: [published]
workflow_dispatch:
jobs:
call-iconica-component-documentation-workflow:
uses: Iconica-Development/.github/.github/workflows/component-documentation.yml@master
secrets: inherit
permissions: write-all

7
.gitignore vendored
View file

@ -30,10 +30,13 @@ migrate_working_dir/
build/
.metadata
example/web
example/android
example/ios
example/macos
example/windows
example/linux
example/linux
# FVM Version Cache
.fvm/
.fmvrc

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,24 @@
## 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
- Added an extra widget builder to add more customizability, for example to add 'today' and 'close' buttons.
## 4.0.0
- Controller has to be specified given to the [DragDownDateTimePicker] so the date can be changed outside of the widget itself.
## 3.3.3
- Added option for date box theme for marked dates and a boolean to use it
## 3.3.2
- Fixed size of Date_Time_Picker
## 3.3.1
- Fixed seperated bar theme from icon color

194
CONTRIBUTING.md Normal file
View file

@ -0,0 +1,194 @@
# Contributing
First off, thanks for taking the time to contribute! ❤️
All types of contributions are encouraged and valued.
See the [Table of Contents](#table-of-contents) for different ways to help and details about how we handle them.
Please make sure to read the relevant section before making your contribution.
It will make it a lot easier for us maintainers and smooth out the experience for all involved.
Iconica looks forward to your contributions. 🎉
## Table of contents
- [Code of conduct](#code-of-conduct)
- [I Have a Question](#i-have-a-question)
- [I Want To Contribute](#i-want-to-contribute)
- [Reporting Bugs](#reporting-bugs)
- [Contributing code](#contributing-code)
## Code of conduct
### Legal notice
When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license.
All accepted pull requests and other additions to this project will be considered intellectual property of Iconica.
All repositories should be kept clean of jokes, easter eggs and other unnecessary additions.
## I have a question
If you want to ask a question, we assume that you have read the available documentation found within the code.
Before you ask a question, it is best to search for existing issues that might help you.
In case you have found a suitable issue but still need clarification, you can ask your question
It is also advisable to search the internet for answers first.
If you then still feel the need to ask a question and need clarification, we recommend the following:
- Open an issue.
- Provide as much context as you can about what you're running into.
We will then take care of the issue as soon as possible.
## I want to contribute
### Reporting bugs
<!-- omit in toc -->
**Before submitting a bug report**
A good bug report shouldn't leave others needing to chase you up for more information.
Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report.
Please complete the following steps in advance to help us fix any potential bug as fast as possible.
- Make sure that you are using the latest version.
- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (If you are looking for support, you might want to check [this section](#i-have-a-question)).
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error.
- Also make sure to search the internet (including Stack Overflow) to see if users outside of Iconica have discussed the issue.
- Collect information about the bug:
- Stack trace (Traceback)
- OS, Platform and Version (Windows, Linux, macOS, x86, ARM)
- Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant.
- Time and date of occurance
- Describe the expected result and actual result
- Can you reliably reproduce the issue? And can you also reproduce it with older versions? Describe all steps that lead to the bug.
Once it's filed:
- The project team will label the issue accordingly.
- A team member will try to reproduce the issue with your provided steps.
If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for additional information.
- If the team is able to reproduce the issue, it will be moved into the backlog, as well as marked with a priority, and the issue will be left to be [implemented by someone](#contributing-code).
### Contributing code
When you start working on your contribution, make sure you are aware of the relevant documentation and the functionality of the component you are working on.
When writing code, follow the style guidelines set by Dart: [Effective Dart](https://Dart.dev/guides/language/effective-Dart). This contains most information you will need to write clean Dart code that is well documented.
**Documentation**
As Effective Dart indicates, documenting your public methods with Dart doc comments is recommended.
Aside from Effective Dart, we require specific information in the documentation of a method:
At the very least, your documentation should first name what the code does, then followed below by requirements for calling the method, the result of the method.
Any references to internal variables or other methods should be done through [var] to indicate a reference.
If the method or class is complex enough (determined by the reviewers) an example is required.
If unsure, add an example in the docs using code blocks.
For classes and methods, document the individual parameters with their implications.
> Tip: Remember that the shortest documentation can be written by having good descriptive names in the first place.
An example:
```Dart
library iconica_utilities.bidirectional_sorter;
part 'sorter.Dart';
part 'enum.Dart';
/// Generic sort method, allow sorting of list with primitives or complex types.
/// Uses [SortDirection] to determine the direction, either Ascending or Descending,
/// Gets called on [List] toSort of type [T] which cannot be shorter than 2.
/// Optionally for complex types a [Comparable] [Function] can be given to compare complex types.
/// ```
/// List<TestObject> objects = [];
/// for (int i = 0; i < 10; i++) {
/// objects.add(TestObject(name: "name", id: i));
/// }
///
/// sort<TestObject>(
/// SortDirection.descending, objects, (object) => object.id);
///
/// ```
/// In the above example a list of TestObjects is created, and then sorted in descending order.
/// If the implementation of TestObject is as following:
/// ```
/// class TestObject {
/// final String name;
/// final int id;
///
/// TestObject({required this.name, required this.id});
/// }
/// ```
/// And the list is logged to the console, the following will appear:
/// ```
/// [name9, name8, name7, name6, name5, name4, name3, name2, name1, name0]
/// ```
void sort<T>(
/// Determines the sorting direction, can be either Ascending or Descending
SortDirection sortDirection,
/// Incoming list, which gets sorted
List<T> toSort, [
/// Optional comparable, which is only necessary for complex types
SortFieldGetter<T>? sortValueCallback,
]) {
if (toSort.length < 2) return;
assert(
toSort.whereType<Comparable>().isNotEmpty || sortValueCallback != null);
BidirectionalSorter<T>(
sortInstructions: <SortInstruction<T>>[
SortInstruction(
sortValueCallback ?? (t) => t as Comparable, sortDirection),
],
).sort(toSort);
}
/// same functionality as [sort] but with the added functionality
/// of sorting multiple values
void sortMulti<T>(
/// Incoming list, which gets sorted
List<T> toSort,
/// list of comparables to sort multiple values at once,
/// priority based on index
List<SortInstruction<T>> sortValueCallbacks,
) {
if (toSort.length < 2) return;
assert(sortValueCallbacks.isNotEmpty);
BidirectionalSorter<T>(
sortInstructions: sortValueCallbacks,
).sort(toSort);
}
```
**Tests**
For each public method that was created, excluding widgets, which contains any form of logic (e.g. Calculations, predicates or major side-effects) tests are required.
A set of tests is written for each method, covering at least each path within the method. For example:
```Dart
void foo() {
try {
var bar = doSomething();
if (bar) {
doSomethingElse();
} else {
doSomethingCool();
}
} catch (_) {
displayError();
}
}
```
The method above should result in 3 tests:
1. A test for the path leading to displayError by the cause of an exception
2. A test for if bar is true, resulting in doSomethingElse()
3. A test for if bar is false, resulting in the doSomethingCool() method being called.
This means that we require 100% coverage of each method you test.

View file

@ -4,6 +4,9 @@
Fluter DateTime Picker is a package you can use to implement an Calandar to pick dates and ust them in your Flutter app.
Figma Design that defines this component (only accessible for Iconica developers): https://www.figma.com/file/4WkjwynOz5wFeFBRqTHPeP/Iconica-Design-System?type=design&node-id=357%3A3345&mode=design&t=XulkAJNPQ32ARxWh-1
Figma clickable prototype that demonstrates this component (only accessible for Iconica developers): https://www.figma.com/proto/4WkjwynOz5wFeFBRqTHPeP/Iconica-Design-System?type=design&node-id=340-611&viewport=-1987%2C15%2C0.3&t=XulkAJNPQ32ARxWh-0&scaling=min-zoom&starting-point-node-id=381%3A8571&show-proto-sidebar=1
## Features
### DragDownDateTimePicker
@ -36,7 +39,7 @@ Please file any issues, bugs or feature request as an issue on our [GitHub](http
## Want to contribute
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](../CONTRIBUTING.md) and send us your [pull request](https://github.com/Iconica-Development/flutter_date_time_picker/pulls).
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](./CONTRIBUTING.md) and send us your [pull request](https://github.com/Iconica-Development/flutter_date_time_picker/pulls).
## Author

3
example/.gitignore vendored
View file

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

View file

@ -1,30 +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.
version:
revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
channel: stable
project_type: app
# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
- platform: web
create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
# User provided section
# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'

View file

@ -156,32 +156,38 @@ class DatePickerDemo extends StatelessWidget {
),
DragDownDateTimePicker(
onTimerPickerSheetChange: (value) {},
alwaysUse24HourFormat: true,
dateTimePickerTheme: const DateTimePickerTheme(
backgroundColor: Colors.white,
markedIndicatorColor: Colors.red,
baseTheme: DateBoxTheme(
controller: DateTimePickerController(
initialDate: DateTime.now(),
),
configuration: DateTimePickerConfiguration(
highlightToday: true,
alwaysUse24HourFormat: true,
markedDates: [DateTime.now().subtract(const Duration(days: 1))],
theme: const DateTimePickerTheme(
backgroundColor: Colors.white,
textStyle: TextStyle(color: Colors.black),
),
selectedTheme: DateBoxTheme(
backgroundColor: Color(0x4BF44336),
textStyle: TextStyle(
color: Colors.red,
markedIndicatorColor: Colors.red,
baseTheme: DateBoxTheme(
backgroundColor: Colors.white,
textStyle: TextStyle(color: Colors.black),
),
),
highlightTheme: DateBoxTheme(
backgroundColor: Colors.red,
textStyle: TextStyle(
color: Colors.white,
selectedTheme: DateBoxTheme(
backgroundColor: Color(0x4BF44336),
textStyle: TextStyle(
color: Colors.red,
),
),
highlightTheme: DateBoxTheme(
backgroundColor: Colors.red,
textStyle: TextStyle(
color: Colors.white,
),
),
barTheme: DateTimePickerBarTheme(
barColor: Colors.black,
barOpacity: 1,
),
),
barTheme: DateTimePickerBarTheme(
barColor: Colors.black,
barOpacity: 1,
),
),
markedDates: [DateTime.now().subtract(const Duration(days: 1))],
),
],
),

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: "3.3.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: ../
flutter_localizations:
sdk: flutter
intl: ^0.18.0 # Add this line
intl: any
dev_dependencies:
flutter_test:

View file

@ -5,6 +5,8 @@
library flutter_date_time_picker;
export 'src/drag_down_date_time_picker.dart' show DragDownDateTimePicker;
export 'src/utils/date_time_picker_controller.dart';
export 'src/utils/date_time_picker_config.dart';
export 'src/overlay_date_time_picker.dart' show OverlayDateTimePicker;
export 'src/models/date_constraint.dart';
export 'src/enums/date_box_shape.dart';

View file

@ -3,7 +3,8 @@
// SPDX-License-Identifier: BSD-3-Clause
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/src/models/date_time_picker_theme.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_config.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
import 'package:flutter_date_time_picker/src/widgets/month_date_time_picker/month_date_time_picker_sheet.dart';
import 'package:flutter_date_time_picker/src/widgets/week_date_time_picker/week_date_time_picker_sheet.dart';
@ -15,59 +16,23 @@ class DragDownDateTimePicker extends StatefulWidget {
/// Both views can be dragged sideways to show the next or previous week/month.
const DragDownDateTimePicker({
this.dateTimePickerTheme = const DateTimePickerTheme(),
this.header,
required this.controller,
required this.configuration,
this.onTimerPickerSheetChange,
this.onTapDay,
this.highlightToday = true,
this.wrongTimeDialog,
this.alwaysUse24HourFormat,
this.pickTime = false,
this.initialDate,
this.markedDates,
this.disabledDates,
this.disabledTimes,
this.child,
super.key,
});
final DateTimePickerController controller;
final DateTimePickerConfiguration configuration;
/// The child contained by the DatePicker.
final Widget? child;
/// A [Widget] to display when the user picks a disabled time in the [TimePickerDialog]
final Widget? wrongTimeDialog;
/// Visual properties for the [DragDownDateTimePicker]
final DateTimePickerTheme dateTimePickerTheme;
/// Widget shown at the top of the [DragDownDateTimePicker]
final Widget? header;
/// Callback that provides the date tapped on as a [DateTime] object.
final Function(DateTime)? onTapDay;
/// Whether the current day should be highlighted in the [DragDownDateTimePicker]
final bool highlightToday;
/// a [bool] to set de clock on [TimePickerDialog] to a fixed 24 or 12-hour format.
/// By default this gets determined by the settings on the user device.
final bool? alwaysUse24HourFormat;
/// [pickTime] is a [bool] that determines if the user is able to pick a time after picking a date using the [TimePickerDialog].
final bool pickTime;
/// indicates the starting date. Default is [DateTime.now()]
final DateTime? initialDate;
/// [markedDates] contain the dates [DateTime] that will be marked in the [DragDownDateTimePicker] by a small dot.
final List<DateTime>? markedDates;
/// a [List] of [DateTime] objects that will be disabled and cannot be interacted with whatsoever.
final List<DateTime>? disabledDates;
/// a [List] of [TimeOfDay] objects that cannot be picked in the [TimePickerDialog].
final List<TimeOfDay>? disabledTimes;
/// Function that gets called when the view changes from week to month or vice versa.
/// The value is the amount of scrolledpixels.
final Function(double)? onTimerPickerSheetChange;
@ -77,7 +42,8 @@ class DragDownDateTimePicker extends StatefulWidget {
}
class _DragDownDateTimePickerState extends State<DragDownDateTimePicker> {
late DateTimePickerController _dateTimePickerController;
late final DateTimePickerController _dateTimePickerController =
widget.controller;
final DraggableScrollableController _dragController =
DraggableScrollableController();
@ -87,20 +53,6 @@ class _DragDownDateTimePickerState extends State<DragDownDateTimePicker> {
super.initState();
initializeDateFormatting();
_dateTimePickerController = DateTimePickerController(
highlightToday: widget.highlightToday,
alwaysUse24HourFormat: widget.alwaysUse24HourFormat,
pickTime: widget.pickTime,
theme: widget.dateTimePickerTheme,
header: widget.header,
markedDates: widget.markedDates,
disabledDates: widget.disabledDates,
disabledTimes: widget.disabledTimes,
onTapDayCallBack: widget.onTapDay,
browsingDate: widget.initialDate ?? DateTime.now(),
selectedDate: widget.initialDate ?? DateTime.now(),
);
_dateTimePickerController.addListener(() {
setState(() {});
});
@ -129,9 +81,9 @@ class _DragDownDateTimePickerState extends State<DragDownDateTimePicker> {
child: DraggableScrollableSheet(
controller: _dragController,
snap: true,
minChildSize: _dateTimePickerController.theme.weekViewSize,
initialChildSize: _dateTimePickerController.theme.weekViewSize,
maxChildSize: _dateTimePickerController.theme.monthViewSize,
minChildSize: widget.configuration.theme.weekViewSize,
initialChildSize: widget.configuration.theme.weekViewSize,
maxChildSize: widget.configuration.theme.monthViewSize,
builder: (context, scrollController) {
double dragSize =
_dragController.isAttached ? _dragController.size : 0;
@ -147,8 +99,7 @@ class _DragDownDateTimePickerState extends State<DragDownDateTimePicker> {
padding: const EdgeInsets.only(bottom: 12.5),
child: Container(
decoration: BoxDecoration(
color:
_dateTimePickerController.theme.backgroundColor,
color: widget.configuration.theme.backgroundColor,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20),
@ -161,21 +112,25 @@ class _DragDownDateTimePickerState extends State<DragDownDateTimePicker> {
],
),
child: dragSize <
_dateTimePickerController
.theme.weekMonthTriggerSize
widget
.configuration.theme.weekMonthTriggerSize
? WeekDateTimePickerSheet(
dateTimePickerController:
_dateTimePickerController,
dateTimePickerConfiguration:
widget.configuration,
weekDateBoxSize: widget
.dateTimePickerTheme.weekDateBoxSize,
.configuration.theme.weekDateBoxSize,
)
: MonthDateTimePickerSheet(
dateTimePickerController:
_dateTimePickerController,
dateTimePickerConfiguration:
widget.configuration,
monthDateBoxSize: widget
.dateTimePickerTheme.monthDateBoxSize,
.configuration.theme.monthDateBoxSize,
monthDatePadding: widget
.dateTimePickerTheme.monthDatePadding,
.configuration.theme.monthDatePadding,
),
),
),

View file

@ -2,15 +2,21 @@
//
// SPDX-License-Identifier: BSD-3-Clause
/// Class representing date constraints for DateTime values.
class DateTimeConstraint {
/// Minimum date constraint.
final DateConstraint min;
/// Maximum date constraint.
final DateConstraint max;
/// Constructs a DateTimeConstraint instance.
const DateTimeConstraint({
this.min = DateConstraint.infinity,
this.max = DateConstraint.infinity,
});
/// Checks if the given date is within the range specified by min and max constraints.
bool inRange(DateTime date) {
return _checkDate(
min,
@ -22,6 +28,7 @@ class DateTimeConstraint {
);
}
/// Checks if the given date is within the date range (ignoring time) specified by min and max constraints.
bool inDateRange(DateTime date) {
return _checkDate(
min,
@ -33,6 +40,7 @@ class DateTimeConstraint {
);
}
/// Checks if the given date is within the month range specified by min and max constraints.
bool inMonthRange(DateTime date) {
return _checkDate(
min,
@ -46,6 +54,7 @@ class DateTimeConstraint {
);
}
/// Checks if the given date is within the year range specified by min and max constraints.
bool inYearRange(DateTime date) {
return _checkDate(
min,
@ -57,6 +66,7 @@ class DateTimeConstraint {
);
}
/// Strips the given date to date only (no time information).
DateTime _stripToDateOnly(DateTime date) {
return DateTime(
date.year,
@ -65,6 +75,7 @@ class DateTimeConstraint {
);
}
/// Strips the given date to month only.
DateTime _stripToMonthsOnly(DateTime date) {
return DateTime(
date.year,
@ -73,6 +84,7 @@ class DateTimeConstraint {
);
}
/// Strips the given date to year only.
DateTime _stripToYearsOnly(DateTime date) {
return DateTime(
date.year,
@ -81,6 +93,7 @@ class DateTimeConstraint {
);
}
/// Checks if the date constraint is met.
bool _checkDate(DateConstraint constraint, bool Function() checker) {
if (!constraint.isInfinite) {
return checker();
@ -89,12 +102,19 @@ class DateTimeConstraint {
}
}
/// Class representing a date constraint.
class DateConstraint {
/// Date constraint representing infinity.
static const DateConstraint infinity =
DateConstraint(date: null, isInfinite: true);
/// The date associated with the constraint.
final DateTime? date;
/// Indicates if the constraint is infinite.
final bool isInfinite;
/// Constructs a DateConstraint instance.
const DateConstraint({this.date, this.isInfinite = false})
: assert(
!(date != null && isInfinite),

View file

@ -16,13 +16,21 @@ class DateTimePickerTheme {
this.paginationSize = 25,
this.weekDateBoxSize = 35,
this.monthDateBoxSize = 45,
this.markedIndicatorColor,
this.markedIndicatorColor = Colors.blue,
this.markedTheme = const DateBoxTheme(
backgroundColor: Colors.blue,
textStyle: TextStyle(color: Colors.white),
),
this.useMarkedTheme = false,
this.dateBoxShape = DateBoxShape.roundedRectangle,
this.backgroundColor = Colors.white,
this.weekViewSize = 0.2,
this.monthViewSize = 0.6,
this.weekMonthTriggerSize = 0.3,
this.shapeDecoration,
this.border,
this.boxShadows,
this.borderRadius,
this.baseTheme = const DateBoxTheme(
backgroundColor: Colors.white,
textStyle: TextStyle(color: Colors.black)),
@ -75,6 +83,12 @@ class DateTimePickerTheme {
/// The color used for a indicator for a marked date.
final Color? markedIndicatorColor;
/// This theme is used for marked dates
final DateBoxTheme markedTheme;
/// This boolean is to determine if the markedTheme should be used for the marked dates
final bool useMarkedTheme;
/// The color used for a background of the date picker.
final Color backgroundColor;
@ -110,4 +124,13 @@ class DateTimePickerTheme {
/// The padding surrounding the calendar
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

@ -4,12 +4,16 @@
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/src/models/date_time_picker_theme.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_config.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
import 'package:flutter_date_time_picker/src/models/date_constraint.dart';
import 'package:flutter_date_time_picker/src/widgets/overlay_date_time_picker/overlay.dart';
import 'package:intl/date_symbol_data_local.dart';
/// `OverlayDateTimePicker` is a StatefulWidget that represents a date time picker overlay.
/// It provides a way to select a date and time from an overlay that can be positioned relative to other widgets.
class OverlayDateTimePicker extends StatefulWidget {
/// Creates a new instance of `OverlayDateTimePicker`.
const OverlayDateTimePicker({
this.theme = const DateTimePickerTheme(),
this.textStyle = const TextStyle(),
@ -31,6 +35,7 @@ class OverlayDateTimePicker extends StatefulWidget {
this.dateTimeConstraint = const DateTimeConstraint(),
this.onNextPageButtonBuilder,
this.onPreviousPageButtonBuilder,
this.extraWidgetBuilder,
this.isShown = false,
}) : assert(child != null || buttonBuilder != null);
@ -95,6 +100,9 @@ class OverlayDateTimePicker extends StatefulWidget {
final Widget Function(void Function()? onPressed)?
onPreviousPageButtonBuilder;
/// a [Widget] that can add custom widgets beneath the [OverlayDateTimeContent] for enhanced functionality
final Widget? extraWidgetBuilder;
@override
State<OverlayDateTimePicker> createState() => _OverlayDateTimePickerState();
}
@ -106,6 +114,15 @@ class _OverlayDateTimePickerState extends State<OverlayDateTimePicker> {
late bool _isShown = widget.isShown;
late final DateTimePickerController _dateTimePickerController;
late final _dateTimePickerConfiguration = DateTimePickerConfiguration(
highlightToday: widget.highlightToday,
alwaysUse24HourFormat: widget.alwaysUse24HourFormat,
pickTime: widget.pickTime,
theme: widget.theme,
markedDates: widget.markedDates,
disabledDates: widget.disabledDates,
disabledTimes: widget.disabledTimes,
);
_DropdownRoute? _dropdownRoute;
@ -114,21 +131,13 @@ class _OverlayDateTimePickerState extends State<OverlayDateTimePicker> {
super.initState();
initializeDateFormatting();
_dateTimePickerController = DateTimePickerController(
highlightToday: widget.highlightToday,
alwaysUse24HourFormat: widget.alwaysUse24HourFormat,
pickTime: widget.pickTime,
theme: widget.theme,
markedDates: widget.markedDates,
disabledDates: widget.disabledDates,
disabledTimes: widget.disabledTimes,
onTapDayCallBack: (date) {
widget.onTapDay?.call(date);
if (widget.closeOnSelectDate) {
Navigator.of(context).pop();
}
},
browsingDate: widget.initialDate ?? DateTime.now(),
selectedDate: widget.initialDate ?? DateTime.now(),
initialDate: widget.initialDate ?? DateTime.now(),
);
}
@ -232,12 +241,14 @@ class _OverlayDateTimePickerState extends State<OverlayDateTimePicker> {
weekdayTextStyle: widget.textStyle,
size: widget.size,
controller: _dateTimePickerController,
configuration: _dateTimePickerConfiguration,
showWeekDays: true,
onNextDate: nextDate,
onPreviousDate: previousDate,
dateTimeConstraint: widget.dateTimeConstraint,
onNextPageButtonChild: widget.onNextPageButtonBuilder,
onPreviousPageButtonChild: widget.onPreviousPageButtonBuilder,
extraWidgetBuilder: widget.extraWidgetBuilder,
),
),
),

View file

@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: 2023 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/flutter_date_time_picker.dart';
/// `DateTimePickerConfiguration` is a class that holds the configuration for a DateTimePicker.
/// It provides various options to customize the behavior and appearance of the DateTimePicker.
class DateTimePickerConfiguration {
/// Creates a new instance of `DateTimePickerConfiguration`.
DateTimePickerConfiguration({
required this.theme,
this.pickTime = false,
this.highlightToday = true,
this.alwaysUse24HourFormat,
this.header,
this.wrongTimeDialog,
this.markedDates,
this.disabledDates,
this.disabledTimes,
});
/// Whether the current day should be highlighted in the [DragDownDateTimePicker]
final bool highlightToday;
/// a [bool] to set de clock on [TimePickerDialog] to a fixed 24 or 12-hour format.
/// By default this gets determined by the settings on the user device.
final bool? alwaysUse24HourFormat;
/// Widget shown at the top of the [DragDownDateTimePicker]
final Widget? header;
final Widget? wrongTimeDialog;
/// Visual properties for the [DragDownDateTimePicker]
final DateTimePickerTheme theme;
/// [markedDates] contain the dates [DateTime] that will be marked in the [DragDownDateTimePicker] by a small dot.
final List<DateTime>? markedDates;
/// a [List] of [DateTime] objects that will be disabled and cannot be interacted with whatsoever.
final List<DateTime>? disabledDates;
/// a [List] of [TimeOfDay] objects that cannot be picked in the [TimePickerDialog].
final List<TimeOfDay>? disabledTimes;
/// [pickTime] is a [bool] that determines if the user is able to pick a time after picking a date using the [TimePickerDialog].
final bool pickTime;
}

View file

@ -3,44 +3,33 @@
// SPDX-License-Identifier: BSD-3-Clause
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/src/models/date_time_picker_theme.dart';
/// Controller for managing date and time selection.
class DateTimePickerController extends ChangeNotifier {
DateTimePickerController({
required this.theme,
required this.highlightToday,
required this.pickTime,
required this.browsingDate,
required this.selectedDate,
this.alwaysUse24HourFormat,
this.header,
this.wrongTimeDialog,
this.markedDates,
this.disabledDates,
this.disabledTimes,
this.onTapDayCallBack,
});
final PageController _pageController = PageController(initialPage: 1);
final bool highlightToday;
final bool? alwaysUse24HourFormat;
final Widget? header;
final Widget? wrongTimeDialog;
final DateTimePickerTheme theme;
final List<DateTime>? markedDates;
final List<DateTime>? disabledDates;
final List<TimeOfDay>? disabledTimes;
final bool pickTime;
/// Callback that provides the date tapped on as a [DateTime] object.
final Function(DateTime)? onTapDayCallBack;
DateTime browsingDate;
DateTime selectedDate;
/// Callback triggered when the date scrolls to the border.
final Function(DateTime)? onBorderScrollCallback;
/// Initial date.
final DateTime initialDate;
/// Page controller for managing the date selection.
final PageController _pageController = PageController(initialPage: 1);
/// The currently browsed date.
late DateTime browsingDate = initialDate;
/// The selected date.
late DateTime selectedDate = initialDate;
/// Constructs a DateTimePickerController.
DateTimePickerController({
required this.initialDate,
this.onTapDayCallBack,
this.onBorderScrollCallback,
});
@override
void dispose() {
@ -48,25 +37,23 @@ class DateTimePickerController extends ChangeNotifier {
super.dispose();
}
/// Callback for page change.
void onPageChanged(DateTime date) {
Future.delayed(
const Duration(milliseconds: 250),
() {
browsingDate = date;
notifyListeners();
_pageController.jumpToPage(1);
},
);
}
/// Callback for tapping a day.
void onTapDay(DateTime date) {
browsingDate = date;
selectedDate = date;
notifyListeners();
if (onTapDayCallBack != null) {
onTapDayCallBack!.call(
date,
@ -74,13 +61,24 @@ class DateTimePickerController extends ChangeNotifier {
}
}
/// Callback for scrolling to the border.
void onBorderScroll(DateTime date) {
browsingDate = date;
selectedDate = date;
notifyListeners();
onBorderScrollCallback?.call(date);
}
/// Retrieves the page controller.
PageController get pageController => _pageController;
/// Sets the browsing date.
void setBrowsingDate(DateTime date) {
browsingDate = date;
notifyListeners();
}
/// Sets the selected date.
void setSelectedDate(DateTime date) {
selectedDate = date;
notifyListeners();

View file

@ -4,10 +4,15 @@
import 'package:flutter/material.dart';
/// Custom scroll physics for locking page scroll.
class LockingPageScrollPhysics extends ScrollPhysics {
/// Function to determine if scrolling to the next page is allowed.
final bool Function() allowedNextPage;
/// Function to determine if scrolling to the previous page is allowed.
final bool Function() allowedPreviousPage;
/// Constructs LockingPageScrollPhysics.
const LockingPageScrollPhysics({
required this.allowedNextPage,
required this.allowedPreviousPage,

View file

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/flutter_date_time_picker.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
import 'package:flutter_date_time_picker/src/widgets/overlay_date_time_picker/overlay.dart';
class DateTimePicker extends StatefulWidget {
@ -38,7 +37,7 @@ class DateTimePicker extends StatefulWidget {
final List<TimeOfDay>? disabledTimes;
/// a [Size] that indicates the size of the overlay
final Size size;
final Size? size;
/// [buttonBuilder] is a method for building the button that can trigger the overlay to appear
final Widget Function(Key key, void Function() onPressed)? buttonBuilder;
@ -75,7 +74,7 @@ class DateTimePicker extends StatefulWidget {
this.markedDates,
this.disabledDates,
this.disabledTimes,
required this.size,
this.size,
this.buttonBuilder,
this.closeOnSelectDate = false,
this.showWeekDays = true,
@ -92,6 +91,15 @@ class DateTimePicker extends StatefulWidget {
class _DateTimePickerState extends State<DateTimePicker> {
late final DateTimePickerController _dateTimePickerController =
DateTimePickerController(
onTapDayCallBack: (date) {
widget.onTapDay?.call(date);
if (widget.closeOnSelectDate) {
Navigator.of(context).pop();
}
},
initialDate: widget.initialDate ?? DateTime.now(),
);
late final _dateTimePickerConfiguration = DateTimePickerConfiguration(
highlightToday: widget.highlightToday,
alwaysUse24HourFormat: widget.alwaysUse24HourFormat,
pickTime: widget.pickTime,
@ -99,28 +107,25 @@ class _DateTimePickerState extends State<DateTimePicker> {
markedDates: widget.markedDates,
disabledDates: widget.disabledDates,
disabledTimes: widget.disabledTimes,
onTapDayCallBack: (date) {
widget.onTapDay?.call(date);
if (widget.closeOnSelectDate) {
Navigator.of(context).pop();
}
},
browsingDate: widget.initialDate ?? DateTime.now(),
selectedDate: widget.initialDate ?? DateTime.now(),
);
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return Container(
decoration: (widget.theme.shapeDecoration == null)
? BoxDecoration(
color: widget.theme.backgroundColor,
borderRadius: const BorderRadius.all(Radius.circular(16)),
boxShadow: [
BoxShadow(
blurRadius: 5,
color: Colors.black.withOpacity(0.25),
),
],
borderRadius: widget.theme.borderRadius ??
const BorderRadius.all(Radius.circular(16)),
border: widget.theme.border,
boxShadow: widget.theme.boxShadows ??
[
BoxShadow(
blurRadius: 5,
color: Colors.black.withOpacity(0.25),
),
],
)
: ShapeDecoration(
shape: widget.theme.shapeDecoration!.shape,
@ -139,15 +144,16 @@ class _DateTimePickerState extends State<DateTimePicker> {
: widget.theme.shapeDecoration!.shadows,
),
child: SizedBox(
width: widget.size.width,
height: widget.size.height,
width: widget.size?.width ?? size.width,
height: widget.size?.height ?? size.height,
child: Padding(
padding: widget.theme.calenderPadding,
child: OverlayDateTimeContent(
theme: widget.theme,
weekdayTextStyle: widget.weekdayTextStyle,
size: widget.size,
size: widget.size ?? Size(size.width, size.height),
controller: _dateTimePickerController,
configuration: _dateTimePickerConfiguration,
showWeekDays: true,
onNextDate: nextDate,
onPreviousDate: previousDate,

View file

@ -1,6 +1,15 @@
import 'package:flutter/material.dart';
/// `MarkedIcon` is a StatelessWidget that represents a marked icon.
/// It provides a colored circular icon that can be used to indicate a marked state.
class MarkedIcon extends StatelessWidget {
/// Creates a new instance of `MarkedIcon`.
///
/// The [width] and [height] parameters must not be null.
///
/// * [width]: The width of the icon.
/// * [height]: The height of the icon.
/// * [color]: The color of the icon. If null, the indicator color from the current theme is used.
const MarkedIcon({
super.key,
this.color,

View file

@ -8,22 +8,35 @@ import 'package:flutter_date_time_picker/src/extensions/date_time.dart';
import 'package:flutter_date_time_picker/src/extensions/time_of_day.dart';
import 'package:flutter_date_time_picker/src/models/date_box_current_theme.dart';
import 'package:flutter_date_time_picker/src/models/date_time_picker_theme.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_config.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
import 'package:flutter_date_time_picker/src/widgets/marked_icon.dart';
import 'package:intl/intl.dart';
/// `MonthDateTimePicker` is a StatelessWidget that represents a picker for a date within a month.
/// It provides a grid of dates for the month and allows the user to select a date.
class MonthDateTimePicker extends StatelessWidget {
/// Creates a new instance of `MonthDateTimePicker`.
const MonthDateTimePicker({
required this.date,
required this.dateTimePickerController,
required this.monthDateBoxSize,
required this.dateTimePickerConfiguration,
Key? key,
}) : super(key: key);
/// The date of the month to display.
final DateTime date;
/// The controller for managing date and time selection.
final DateTimePickerController dateTimePickerController;
/// The size of each date box in the month grid.
final double monthDateBoxSize;
/// The configuration for the date and time picker.
final DateTimePickerConfiguration dateTimePickerConfiguration;
@override
Widget build(BuildContext context) {
int daysToSkip = DateTime(
@ -39,7 +52,7 @@ class MonthDateTimePicker extends StatelessWidget {
child: Center(
child: Column(
children: [
if (dateTimePickerController.theme.monthWeekDayHeaders)
if (dateTimePickerConfiguration.theme.monthWeekDayHeaders)
Row(
children: List.generate(
7,
@ -51,8 +64,8 @@ class MonthDateTimePicker extends StatelessWidget {
date.daysOfWeek().elementAt(index),
)
.toUpperCase()[0],
style:
dateTimePickerController.theme.baseTheme.textStyle,
style: dateTimePickerConfiguration
.theme.baseTheme.textStyle,
),
),
),
@ -79,8 +92,11 @@ class MonthDateTimePicker extends StatelessWidget {
return const SizedBox.shrink();
}
currentDateBoxTheme = determineCurrentDateBoxTheme(context,
addedIndex, daysToSkip, dateTimePickerController.theme);
currentDateBoxTheme = determineCurrentDateBoxTheme(
context,
addedIndex,
daysToSkip,
dateTimePickerConfiguration.theme);
return GestureDetector(
onTap: isDisabled(
@ -99,23 +115,24 @@ class MonthDateTimePicker extends StatelessWidget {
timeOfDay = const TimeOfDay(hour: 0, minute: 0);
if (dateTimePickerController.pickTime) {
if (dateTimePickerConfiguration.pickTime) {
timeOfDay = await displayTimePicker(
context, dateTimePickerController);
context, dateTimePickerConfiguration);
}
if (dateTimePickerController.wrongTimeDialog !=
if (dateTimePickerConfiguration.wrongTimeDialog !=
null) {
if (timeOfDay != null &&
timeOfDay.containsAny(
dateTimePickerController.disabledTimes ??
dateTimePickerConfiguration
.disabledTimes ??
[],
)) {
if (context.mounted) {
showDialog(
context: context,
builder: (context) =>
dateTimePickerController
dateTimePickerConfiguration
.wrongTimeDialog!,
);
}
@ -138,8 +155,8 @@ class MonthDateTimePicker extends StatelessWidget {
vertical: 5, horizontal: 5),
decoration: BoxDecoration(
color: currentDateBoxTheme.backgroundColor,
borderRadius:
_determineBorderRadius(dateTimePickerController),
borderRadius: _determineBorderRadius(
dateTimePickerConfiguration),
),
height: monthDateBoxSize,
width: monthDateBoxSize,
@ -157,7 +174,7 @@ class MonthDateTimePicker extends StatelessWidget {
MarkedIcon(
width: monthDateBoxSize / 4,
height: monthDateBoxSize / 4,
color: dateTimePickerController
color: dateTimePickerConfiguration
.theme.markedIndicatorColor,
),
],
@ -181,7 +198,7 @@ class MonthDateTimePicker extends StatelessWidget {
date.month,
index + 1 - daysToSkip,
).equals(
dateTimePickerController.highlightToday
dateTimePickerConfiguration.highlightToday
? DateTime.now()
: dateTimePickerController.selectedDate,
);
@ -228,7 +245,7 @@ class MonthDateTimePicker extends StatelessWidget {
date.month,
index + 1 - daysToSkip,
).containsAny(
dateTimePickerController.disabledDates ?? [],
dateTimePickerConfiguration.disabledDates ?? [],
);
}
@ -246,7 +263,7 @@ class MonthDateTimePicker extends StatelessWidget {
date.month,
index + 1 - daysToSkip,
).equals(
dateTimePickerController.highlightToday
dateTimePickerConfiguration.highlightToday
? DateTime.now()
: dateTimePickerController.selectedDate,
) &&
@ -255,13 +272,13 @@ class MonthDateTimePicker extends StatelessWidget {
date.month,
index + 1 - daysToSkip,
).containsAny(
dateTimePickerController.markedDates ?? [],
dateTimePickerConfiguration.markedDates ?? [],
);
}
BorderRadius _determineBorderRadius(
DateTimePickerController dateTimePickerController) {
switch (dateTimePickerController.theme.dateBoxShape) {
DateTimePickerConfiguration dateTimePickerConfiguration) {
switch (dateTimePickerConfiguration.theme.dateBoxShape) {
case DateBoxShape.circle:
return BorderRadius.circular(monthDateBoxSize * 2);
case DateBoxShape.rectangle:
@ -273,7 +290,7 @@ class MonthDateTimePicker extends StatelessWidget {
}
displayTimePicker(BuildContext context,
DateTimePickerController dateTimePickerController) async {
DateTimePickerConfiguration dateTimePickerConfiguration) async {
return await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
@ -281,7 +298,7 @@ displayTimePicker(BuildContext context,
return MediaQuery(
data: MediaQuery.of(context).copyWith(
alwaysUse24HourFormat:
dateTimePickerController.alwaysUse24HourFormat),
dateTimePickerConfiguration.alwaysUse24HourFormat),
child: child!,
);
});

View file

@ -4,42 +4,54 @@
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/src/extensions/date_time.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_config.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
import 'package:flutter_date_time_picker/src/widgets/month_date_time_picker/month_date_time_picker.dart';
import 'package:intl/intl.dart';
/// `MonthDateTimePickerSheet` is a StatelessWidget that represents a sheet for picking a date within a month.
/// It provides a grid of dates for the month and allows the user to select a date.
class MonthDateTimePickerSheet extends StatelessWidget {
/// Creates a new instance of `MonthDateTimePickerSheet`.
const MonthDateTimePickerSheet({
required this.dateTimePickerController,
required this.dateTimePickerConfiguration,
required this.monthDateBoxSize,
required this.monthDatePadding,
super.key,
});
/// The controller for managing date and time selection.
final DateTimePickerController dateTimePickerController;
/// The configuration for the date and time picker.
final DateTimePickerConfiguration dateTimePickerConfiguration;
/// The size of the month date box.
final double monthDateBoxSize;
/// The padding around the month date.
final EdgeInsetsGeometry monthDatePadding;
@override
Widget build(BuildContext context) {
var theme = dateTimePickerController.theme;
var theme = dateTimePickerConfiguration.theme;
var size = MediaQuery.of(context).size;
return Column(
children: [
if (dateTimePickerController.header != null) ...[
if (dateTimePickerConfiguration.header != null) ...[
Align(
alignment: Alignment.topCenter,
child: dateTimePickerController.header!,
child: dateTimePickerConfiguration.header!,
),
],
Padding(
padding: monthDatePadding,
child: Text(
// use localization to get the month name
DateFormat.yMMMM(Localizations.localeOf(context).toString()).format(
dateTimePickerController.browsingDate,
),
DateFormat.yMMMM(Localizations.localeOf(context).toString())
.format(dateTimePickerController.browsingDate),
style: theme.baseTheme.textStyle!.copyWith(fontSize: 25),
),
),
@ -74,32 +86,38 @@ class MonthDateTimePickerSheet extends StatelessWidget {
},
children: [
MonthDateTimePicker(
date: dateTimePickerController.browsingDate.month == 1
? DateTime(
dateTimePickerController.browsingDate.year - 1, 12, 1)
: DateTime(dateTimePickerController.browsingDate.year,
dateTimePickerController.browsingDate.month - 1, 1),
monthDateBoxSize: monthDateBoxSize,
dateTimePickerController: dateTimePickerController),
date: dateTimePickerController.browsingDate.month == 1
? DateTime(
dateTimePickerController.browsingDate.year - 1, 12, 1)
: DateTime(dateTimePickerController.browsingDate.year,
dateTimePickerController.browsingDate.month - 1, 1),
monthDateBoxSize: monthDateBoxSize,
dateTimePickerController: dateTimePickerController,
dateTimePickerConfiguration: dateTimePickerConfiguration,
),
MonthDateTimePicker(
date: DateTime(
dateTimePickerController.browsingDate.year,
dateTimePickerController.browsingDate.month,
1,
),
dateTimePickerController: dateTimePickerController,
monthDateBoxSize: monthDateBoxSize),
date: DateTime(
dateTimePickerController.browsingDate.year,
dateTimePickerController.browsingDate.month,
1,
),
dateTimePickerController: dateTimePickerController,
dateTimePickerConfiguration: dateTimePickerConfiguration,
monthDateBoxSize: monthDateBoxSize,
),
MonthDateTimePicker(
date: dateTimePickerController.browsingDate.month == 12
? DateTime(
dateTimePickerController.browsingDate.year + 1,
1,
1,
)
: DateTime(dateTimePickerController.browsingDate.year,
dateTimePickerController.browsingDate.month + 1, 1),
dateTimePickerController: dateTimePickerController,
monthDateBoxSize: monthDateBoxSize),
date: dateTimePickerController.browsingDate.month == 12
? DateTime(
dateTimePickerController.browsingDate.year + 1,
1,
1,
)
: DateTime(dateTimePickerController.browsingDate.year,
dateTimePickerController.browsingDate.month + 1, 1),
dateTimePickerController: dateTimePickerController,
dateTimePickerConfiguration: dateTimePickerConfiguration,
monthDateBoxSize: monthDateBoxSize,
),
],
),
),

View file

@ -5,14 +5,17 @@
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/flutter_date_time_picker.dart';
import 'package:flutter_date_time_picker/src/extensions/date_time.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
import 'package:flutter_date_time_picker/src/widgets/overlay_date_time_picker/pickable_date.dart';
import 'package:intl/intl.dart';
/// `DatePicker` is a StatelessWidget that represents a date picker.
/// It provides a way to select a date from a calendar-like interface.
class DatePicker extends StatelessWidget {
/// Creates a new instance of `DatePicker`.
const DatePicker({
super.key,
required this.controller,
required this.configuration,
required this.theme,
required this.weekdayTextStyle,
required this.onSelectDate,
@ -21,12 +24,28 @@ class DatePicker extends StatelessWidget {
required this.dateTimeConstraint,
});
/// The controller for managing date selection.
final DateTimePickerController controller;
/// The configuration for the date picker.
final DateTimePickerConfiguration configuration;
/// The theme for the date picker.
final DateTimePickerTheme theme;
/// The text style for displaying the weekday names.
final TextStyle weekdayTextStyle;
/// Callback function invoked when a date is selected.
final void Function(DateTime date) onSelectDate;
/// The date to display in the picker.
final DateTime date;
/// Whether to show the weekday names.
final bool showWeekDays;
/// The constraint for selecting dates.
final DateTimeConstraint dateTimeConstraint;
@override
@ -44,8 +63,8 @@ class DatePicker extends StatelessWidget {
addedIndex = DateTime.daysPerWeek;
}
int length = DateTime(date.year, date.month).daysInMonth() + daysToSkip;
int daysToAdd = DateTime.daysPerWeek - length % DateTime.daysPerWeek;
int length = DateTime(date.year, date.month).daysInMonth() + daysToSkip % 7;
int daysToAdd = (DateTime.daysPerWeek - length) % DateTime.daysPerWeek;
return Column(
children: [
if (showWeekDays) ...[
@ -65,14 +84,11 @@ class DatePicker extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Text(
// 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
date,
style: weekdayTextStyle
// .copyWith(
// fontStyle: FontStyle.italic,
// fontWeight: FontWeight.w200),
),
// 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
date,
style: weekdayTextStyle,
),
),
),
);
@ -95,7 +111,7 @@ class DatePicker extends StatelessWidget {
return Padding(
padding: const EdgeInsets.all(2.0),
child: PickableDate(
isMarked: controller.markedDates?.any(
isMarked: configuration.markedDates?.any(
(e) => isSameDay(e, todayDate),
) ??
false,
@ -103,7 +119,7 @@ class DatePicker extends StatelessWidget {
isDisabled:
isDisabled(addedIndex + index, daysToSkip, todayDate),
isSelected: controller.selectedDate == todayDate,
isToday: isToday(todayDate) && controller.highlightToday,
isToday: isToday(todayDate) && configuration.highlightToday,
theme: theme,
date: todayDate,
onPressed: onSelectDate,
@ -131,7 +147,7 @@ class DatePicker extends StatelessWidget {
date.month,
index + 1 - daysToSkip,
).containsAny(
controller.disabledDates ?? [],
configuration.disabledDates ?? [],
) ||
!dateTimeConstraint.inRange(date);
}

View file

@ -4,38 +4,67 @@
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/src/models/date_time_picker_theme.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_config.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
import 'package:flutter_date_time_picker/src/utils/locking_page_scroll_physics.dart';
import 'package:flutter_date_time_picker/src/widgets/overlay_date_time_picker/date_picker.dart';
import 'package:flutter_date_time_picker/src/models/date_constraint.dart';
import 'package:intl/intl.dart';
/// `OverlayDateTimeContent` is a StatefulWidget that represents the content of a date time overlay.
/// It provides a way to select a date and navigate between dates within the overlay.
class OverlayDateTimeContent extends StatefulWidget {
/// Creates a new instance of `OverlayDateTimeContent`.
const OverlayDateTimeContent({
super.key,
required this.theme,
required this.weekdayTextStyle,
required this.size,
required this.controller,
required this.configuration,
required this.showWeekDays,
required this.onNextDate,
required this.onPreviousDate,
required this.dateTimeConstraint,
required this.onPreviousPageButtonChild,
required this.onNextPageButtonChild,
this.extraWidgetBuilder,
});
/// The theme for the date time picker.
final DateTimePickerTheme theme;
/// The text style for displaying the weekday names.
final TextStyle weekdayTextStyle;
/// The size of the content.
final Size size;
/// The controller for managing date selection.
final DateTimePickerController controller;
/// The configuration for the date time picker.
final DateTimePickerConfiguration configuration;
/// Whether to show the weekday names.
final bool showWeekDays;
/// The constraint for selecting dates.
final DateTimeConstraint dateTimeConstraint;
/// A widget builder for adding an extra widget.
final Widget? extraWidgetBuilder;
/// A function to provide the next page button.
final Widget Function(void Function()? onPressed)? onNextPageButtonChild;
/// A function to provide the previous page button.
final Widget Function(void Function()? onPressed)? onPreviousPageButtonChild;
/// Callback function invoked when moving to the next date.
final void Function() onNextDate;
/// Callback function invoked when moving to the previous date.
final void Function() onPreviousDate;
@override
@ -91,38 +120,35 @@ class _OverlayDateTimeContentState extends State<OverlayDateTimeContent> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
(widget.onPreviousPageButtonChild != null)
? widget.onPreviousPageButtonChild!(
(widget.dateTimeConstraint.inMonthRange(previousDate))
? _goToPreviousPage
: null,
)
: IconButton(
onPressed:
(widget.dateTimeConstraint.inMonthRange(previousDate))
? _goToPreviousPage
: null,
icon: prevIcon,
iconSize: widget.theme.paginationSize,
),
widget.onPreviousPageButtonChild?.call(
(widget.dateTimeConstraint.inMonthRange(previousDate))
? _goToPreviousPage
: null,
) ??
IconButton(
onPressed:
(widget.dateTimeConstraint.inMonthRange(previousDate))
? _goToPreviousPage
: null,
icon: prevIcon,
iconSize: widget.theme.paginationSize,
),
Text(
monthText,
style: widget.theme.barTheme.textStyle,
),
(widget.onNextPageButtonChild != null)
? widget.onNextPageButtonChild!(
(widget.dateTimeConstraint.inMonthRange(nextDate))
? _goToNextPage
: null,
)
: IconButton(
onPressed:
(widget.dateTimeConstraint.inMonthRange(nextDate))
? _goToNextPage
: null,
icon: nextIcon,
iconSize: widget.theme.paginationSize,
),
widget.onNextPageButtonChild?.call(
(widget.dateTimeConstraint.inMonthRange(nextDate))
? _goToNextPage
: null,
) ??
IconButton(
onPressed: (widget.dateTimeConstraint.inMonthRange(nextDate))
? _goToNextPage
: null,
icon: nextIcon,
iconSize: widget.theme.paginationSize,
),
],
),
Container(
@ -149,6 +175,7 @@ class _OverlayDateTimeContentState extends State<OverlayDateTimeContent> {
children: [
DatePicker(
controller: widget.controller,
configuration: widget.configuration,
onSelectDate: _onSelectDate,
theme: widget.theme,
weekdayTextStyle: widget.weekdayTextStyle,
@ -158,6 +185,7 @@ class _OverlayDateTimeContentState extends State<OverlayDateTimeContent> {
),
DatePicker(
controller: widget.controller,
configuration: widget.configuration,
onSelectDate: _onSelectDate,
theme: widget.theme,
weekdayTextStyle: widget.weekdayTextStyle,
@ -167,6 +195,7 @@ class _OverlayDateTimeContentState extends State<OverlayDateTimeContent> {
),
DatePicker(
controller: widget.controller,
configuration: widget.configuration,
onSelectDate: _onSelectDate,
theme: widget.theme,
weekdayTextStyle: widget.weekdayTextStyle,
@ -176,7 +205,8 @@ class _OverlayDateTimeContentState extends State<OverlayDateTimeContent> {
),
],
),
)
),
widget.extraWidgetBuilder ?? const SizedBox.shrink(),
],
);
}

View file

@ -6,7 +6,21 @@ import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/flutter_date_time_picker.dart';
import 'package:flutter_date_time_picker/src/widgets/marked_icon.dart';
/// `PickableDate` is a StatelessWidget that represents a selectable date.
/// It provides visual feedback based on its state (marked, selected, disabled, etc.).
class PickableDate extends StatelessWidget {
/// Creates a new instance of `PickableDate`.
///
/// The [isMarked], [isSelected], [isDisabled], [isToday], [isOffMonth], [date], [theme], and [onPressed] parameters must not be null.
///
/// * [isMarked]: Indicates whether the date is marked.
/// * [isSelected]: Indicates whether the date is selected.
/// * [isDisabled]: Indicates whether the date is disabled.
/// * [isToday]: Indicates whether the date is the current date.
/// * [isOffMonth]: Indicates whether the date is in the off-month.
/// * [date]: The date that this widget represents.
/// * [theme]: The theme used for styling the widget.
/// * [onPressed]: The callback that is called when the date is pressed.
const PickableDate({
super.key,
required this.isMarked,
@ -64,11 +78,36 @@ class PickableDate extends StatelessWidget {
),
),
if (isMarked) ...[
MarkedIcon(
color: theme.markedIndicatorColor,
width: theme.monthDateBoxSize / 4,
height: theme.monthDateBoxSize / 4,
),
if (theme.useMarkedTheme) ...[
Container(
decoration: BoxDecoration(
border: getMarkedBorder(
isMarked,
),
color: getMarkedColor(
isMarked,
),
borderRadius: getBorderRadius(theme.dateBoxShape),
),
child: Center(
child: Opacity(
opacity: (isDisabled || isOffMonth) ? 0.5 : 1,
child: Text(
date.day.toString(),
style: getMarkedStyle(
isMarked,
),
),
),
),
),
] else ...[
MarkedIcon(
color: theme.markedIndicatorColor,
width: theme.monthDateBoxSize / 4,
height: theme.monthDateBoxSize / 4,
),
]
],
],
),
@ -111,4 +150,23 @@ class PickableDate extends StatelessWidget {
}
return Border.all(color: const Color.fromARGB(0, 255, 255, 255));
}
Color? getMarkedColor(bool isMarked) {
if (isMarked) return theme.markedTheme.backgroundColor;
return null;
}
TextStyle? getMarkedStyle(bool isMarked) {
if (isMarked) return theme.markedTheme.textStyle;
return theme.baseTheme.textStyle;
}
BoxBorder getMarkedBorder(bool isMarked) {
if (isMarked) {
if (theme.markedTheme.borderStyle != null) {
return theme.markedTheme.borderStyle!;
}
}
return Border.all(color: const Color.fromARGB(0, 255, 255, 255));
}
}

View file

@ -7,19 +7,30 @@ import 'package:flutter_date_time_picker/flutter_date_time_picker.dart';
import 'package:flutter_date_time_picker/src/extensions/date_time.dart';
import 'package:flutter_date_time_picker/src/extensions/time_of_day.dart';
import 'package:flutter_date_time_picker/src/models/date_box_current_theme.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
import 'package:flutter_date_time_picker/src/widgets/marked_icon.dart';
import 'package:intl/intl.dart';
/// `WeekDateTimePicker` is a StatelessWidget that represents a picker for a date within a week.
/// It provides a row of dates for the week and allows the user to select a date.
class WeekDateTimePicker extends StatelessWidget {
/// Creates a new instance of `WeekDateTimePicker`.
///
/// The [dateTimePickerController], [dateTimePickerConfiguration], [date], and [weekDateBoxSize] parameters must not be null.
///
/// * [dateTimePickerController]: The controller for the date time picker.
/// * [dateTimePickerConfiguration]: The configuration for the date time picker.
/// * [date]: The date that this widget represents.
/// * [weekDateBoxSize]: The size of the box for each date in the week.
const WeekDateTimePicker({
required this.dateTimePickerController,
required this.dateTimePickerConfiguration,
required this.date,
required this.weekDateBoxSize,
Key? key,
}) : super(key: key);
final DateTimePickerController dateTimePickerController;
final DateTimePickerConfiguration dateTimePickerConfiguration;
final DateTime date;
@ -35,7 +46,7 @@ class WeekDateTimePicker extends StatelessWidget {
late DateBoxCurrentTheme currentDateBoxTheme;
currentDateBoxTheme = determineCurrentDateBoxTheme(
context, index, dateTimePickerController.theme);
context, index, dateTimePickerConfiguration.theme);
return GestureDetector(
onTap: isDisabled(
index,
@ -48,21 +59,21 @@ class WeekDateTimePicker extends StatelessWidget {
timeOfDay = const TimeOfDay(hour: 0, minute: 0);
if (dateTimePickerController.pickTime) {
if (dateTimePickerConfiguration.pickTime) {
timeOfDay = await displayTimePicker(
context, dateTimePickerController);
}
if (dateTimePickerController.wrongTimeDialog != null) {
if (dateTimePickerConfiguration.wrongTimeDialog != null) {
if (timeOfDay != null &&
timeOfDay.containsAny(
dateTimePickerController.disabledTimes ?? [],
dateTimePickerConfiguration.disabledTimes ?? [],
)) {
if (context.mounted) {
showDialog(
context: context,
builder: (context) =>
dateTimePickerController.wrongTimeDialog!,
dateTimePickerConfiguration.wrongTimeDialog!,
);
}
}
@ -90,7 +101,8 @@ class WeekDateTimePicker extends StatelessWidget {
date.daysOfWeek().elementAt(index),
)
.toUpperCase()[0],
style: dateTimePickerController.theme.baseTheme.textStyle,
style:
dateTimePickerConfiguration.theme.baseTheme.textStyle,
),
const Spacer(),
Container(
@ -99,7 +111,7 @@ class WeekDateTimePicker extends StatelessWidget {
decoration: BoxDecoration(
color: currentDateBoxTheme.backgroundColor,
borderRadius:
_determineBorderRadius(dateTimePickerController),
_determineBorderRadius(dateTimePickerConfiguration),
),
child: Stack(
children: [
@ -113,7 +125,7 @@ class WeekDateTimePicker extends StatelessWidget {
MarkedIcon(
width: weekDateBoxSize / 3,
height: weekDateBoxSize / 3,
color: dateTimePickerController
color: dateTimePickerConfiguration
.theme.markedIndicatorColor,
)
],
@ -166,7 +178,7 @@ class WeekDateTimePicker extends StatelessWidget {
bool shouldHighlight(int index) {
return date.daysOfWeek().elementAt(index).equals(
dateTimePickerController.highlightToday
dateTimePickerConfiguration.highlightToday
? DateTime.now()
: dateTimePickerController.selectedDate,
);
@ -183,24 +195,24 @@ class WeekDateTimePicker extends StatelessWidget {
return date
.daysOfWeek()
.elementAt(index)
.containsAny(dateTimePickerController.disabledDates ?? []);
.containsAny(dateTimePickerConfiguration.disabledDates ?? []);
}
bool shouldMark(int index) {
return !date.daysOfWeek().elementAt(index).equals(
dateTimePickerController.highlightToday
dateTimePickerConfiguration.highlightToday
? DateTime.now()
: dateTimePickerController.selectedDate,
) &&
date
.daysOfWeek()
.elementAt(index)
.containsAny(dateTimePickerController.markedDates ?? []);
.containsAny(dateTimePickerConfiguration.markedDates ?? []);
}
BorderRadius _determineBorderRadius(
DateTimePickerController dateTimePickerController) {
switch (dateTimePickerController.theme.dateBoxShape) {
DateTimePickerConfiguration dateTimePickerConfiguration) {
switch (dateTimePickerConfiguration.theme.dateBoxShape) {
case DateBoxShape.circle:
return BorderRadius.circular(weekDateBoxSize * 2);
case DateBoxShape.rectangle:
@ -219,7 +231,7 @@ class WeekDateTimePicker extends StatelessWidget {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
alwaysUse24HourFormat:
dateTimePickerController.alwaysUse24HourFormat),
dateTimePickerConfiguration.alwaysUse24HourFormat),
child: child!,
);
});

View file

@ -4,19 +4,32 @@
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/src/extensions/date_time.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_config.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
import 'package:flutter_date_time_picker/src/widgets/week_date_time_picker/week_date_time_picker.dart';
import 'package:intl/intl.dart';
/// `WeekDateTimePickerSheet` is a StatelessWidget that represents a sheet for picking a date within a week.
/// It provides a header showing the date range for the current week and a PageView of `WeekDateTimePicker` widgets for the previous, current, and next week.
class WeekDateTimePickerSheet extends StatelessWidget {
/// Creates a new instance of `WeekDateTimePickerSheet`.
///
/// The [dateTimePickerController], [dateTimePickerConfiguration], and [weekDateBoxSize] parameters must not be null.
///
/// * [dateTimePickerController]: The controller for the date time picker.
/// * [dateTimePickerConfiguration]: The configuration for the date time picker.
/// * [weekDateBoxSize]: The size of the box for each date in the week.
/// * [showHeader]: Whether to show the header with the date range for the current week. Defaults to false.
const WeekDateTimePickerSheet({
required this.dateTimePickerController,
required this.dateTimePickerConfiguration,
required this.weekDateBoxSize,
this.showHeader = false,
Key? key,
}) : super(key: key);
final DateTimePickerController dateTimePickerController;
final DateTimePickerConfiguration dateTimePickerConfiguration;
final bool showHeader;
final double weekDateBoxSize;
@ -36,14 +49,14 @@ class WeekDateTimePickerSheet extends StatelessWidget {
@override
Widget build(BuildContext context) {
var theme = dateTimePickerController.theme;
var theme = dateTimePickerConfiguration.theme;
return Column(
children: [
if (dateTimePickerController.header != null)
if (dateTimePickerConfiguration.header != null)
Align(
alignment: Alignment.topCenter,
child: dateTimePickerController.header!,
child: dateTimePickerConfiguration.header!,
),
const SizedBox(
height: 10,
@ -80,6 +93,7 @@ class WeekDateTimePickerSheet extends StatelessWidget {
children: [
WeekDateTimePicker(
dateTimePickerController: dateTimePickerController,
dateTimePickerConfiguration: dateTimePickerConfiguration,
date: dateTimePickerController.browsingDate.subtract(
const Duration(days: 7),
),
@ -87,11 +101,13 @@ class WeekDateTimePickerSheet extends StatelessWidget {
),
WeekDateTimePicker(
dateTimePickerController: dateTimePickerController,
dateTimePickerConfiguration: dateTimePickerConfiguration,
date: dateTimePickerController.browsingDate,
weekDateBoxSize: weekDateBoxSize,
),
WeekDateTimePicker(
dateTimePickerController: dateTimePickerController,
dateTimePickerConfiguration: dateTimePickerConfiguration,
date: dateTimePickerController.browsingDate.add(
const Duration(days: 7),
),

View file

@ -1,6 +1,8 @@
name: flutter_date_time_picker
description: A Flutter package for date and time picker.
version: 3.3.1
version: 4.1.0
publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub
environment:
sdk: ">=3.0.0 <4.0.0"
@ -9,7 +11,7 @@ environment:
dependencies:
flutter:
sdk: flutter
intl: any
intl: ">0.18.0 <1.0.0"
dev_dependencies:
flutter_test:

View file

@ -13,7 +13,14 @@ void main() {
home: Scaffold(
appBar: AppBar(),
body: DragDownDateTimePicker(
pickTime: false,
controller: DateTimePickerController(
initialDate: DateTime.now(),
),
configuration: DateTimePickerConfiguration(
theme: const DateTimePickerTheme(),
highlightToday: true,
pickTime: false,
),
child: Container(),
),
),
@ -27,7 +34,14 @@ void main() {
home: Scaffold(
appBar: AppBar(),
body: DragDownDateTimePicker(
pickTime: false,
controller: DateTimePickerController(
initialDate: DateTime.now(),
),
configuration: DateTimePickerConfiguration(
theme: const DateTimePickerTheme(),
highlightToday: true,
pickTime: false,
),
child: Container(),
),
),