fixes with callback

This commit is contained in:
Thomas Klein Langenhorst 2022-09-01 16:09:20 +02:00
parent f90e67fa91
commit 92b7afce0e
38 changed files with 368 additions and 369 deletions

View file

@ -4,7 +4,7 @@
# This file should be version controlled.
version:
revision: f1875d570e39de09040c8f79aa13cc56baab8db1
revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
channel: stable
project_type: app
@ -13,26 +13,26 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: android
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: ios
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: linux
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: macos
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: web
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: windows
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
# User provided section

View file

@ -44,7 +44,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
applicationId "com.iconica.example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion

View file

@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
package="com.iconica.example">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.

View file

@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
package="com.iconica.example">
<application
android:label="example"
android:name="${applicationName}"

View file

@ -1,4 +1,4 @@
package com.example.example
package com.iconica.example
import io.flutter.embedding.android.FlutterActivity

View file

@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
package="com.iconica.example">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.

View file

@ -1,4 +1,3 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

View file

@ -295,7 +295,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.example;
PRODUCT_BUNDLE_IDENTIFIER = com.iconica.example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
@ -424,7 +424,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.example;
PRODUCT_BUNDLE_IDENTIFIER = com.iconica.example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@ -447,7 +447,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.example;
PRODUCT_BUNDLE_IDENTIFIER = com.iconica.example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;

View file

@ -45,5 +45,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>

View file

@ -6,7 +6,7 @@ void main() {
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({super.key});
// This widget is the root of your application.
@override
@ -14,88 +14,23 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(),
home: Scaffold(
appBar: AppBar(
title: const Text('Roster'),
),
body: const DatePickerDemo(),
),
);
}
}
class MyHomePage extends StatelessWidget {
class DatePickerDemo extends StatelessWidget {
const DatePickerDemo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Rooster')),
body: DateTimePicker(
// header: Container(
// height: 100,
// width: MediaQuery.of(context).size.width,
// padding: const EdgeInsets.only(bottom: 10),
// child: Row(
// crossAxisAlignment: CrossAxisAlignment.end,
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// const SizedBox(
// width: 160,
// height: 34,
// child: Center(
// child: Text(
// 'Persoonlijk',
// style: TextStyle(
// fontSize: 16,
// fontWeight: FontWeight.w900,
// ),
// ),
// ),
// ),
// const SizedBox(
// width: 4,
// ),
// Container(
// width: 160,
// height: 34,
// decoration: BoxDecoration(
// color: const Color(0xFF00273D),
// borderRadius: const BorderRadius.all(
// Radius.circular(10),
// ),
// boxShadow: [
// BoxShadow(
// color: const Color(0xFF000000).withOpacity(0.50),
// offset: const Offset(0, 6),
// blurRadius: 9,
// ),
// ],
// ),
// child: const Center(
// child: Text(
// 'Teamplanning',
// style: TextStyle(
// color: Colors.white,
// fontSize: 16,
// fontWeight: FontWeight.w900,
// ),
// ),
// ),
// ),
// ],
// ),
// ),
disabledDates: [DateTime(2022, 8, 26), DateTime(2022, 8, 27)],
markedDates: [DateTime(2022, 8, 28), DateTime(2022, 8, 29)],
disabledTimes: const [TimeOfDay(hour: 12, minute: 0)],
pickTime: true,
child: Container(),
),
);
return DateTimePicker(dateTimePickerTheme: const DateTimePickerTheme(),);
}
}

View file

@ -7,7 +7,7 @@ project(runner LANGUAGES CXX)
set(BINARY_NAME "example")
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
set(APPLICATION_ID "com.example.example")
set(APPLICATION_ID "com.iconica.example")
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -8,7 +8,7 @@
PRODUCT_NAME = example
// The application's bundle identifier
PRODUCT_BUNDLE_IDENTIFIER = com.example.example
PRODUCT_BUNDLE_IDENTIFIER = com.iconica.example
// The copyright displayed in application information
PRODUCT_COPYRIGHT = Copyright © 2022 com.example. All rights reserved.
PRODUCT_COPYRIGHT = Copyright © 2022 com.iconica. All rights reserved.

View file

@ -1,91 +1,24 @@
name: example
description: A new Flutter project.
name: datetime_picker_example
description: DateTimePicker Widget
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: 'none'
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.17.6 <3.0.0"
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
flutter_date_time_picker:
path: ../
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages

View file

@ -1,30 +0,0 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:example/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}

View file

@ -20,6 +20,13 @@ add_executable(${BINARY_NAME} WIN32
# that need different build settings.
apply_standard_settings(${BINARY_NAME})
# Add preprocessor definitions for the build version.
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")
# Disable Windows macros that collide with C++ standard library functions.
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")

View file

@ -60,14 +60,14 @@ IDI_APP_ICON ICON "resources\\app_icon.ico"
// Version
//
#ifdef FLUTTER_BUILD_NUMBER
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
#else
#define VERSION_AS_NUMBER 1,0,0
#define VERSION_AS_NUMBER 1,0,0,0
#endif
#ifdef FLUTTER_BUILD_NAME
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
#if defined(FLUTTER_VERSION)
#define VERSION_AS_STRING FLUTTER_VERSION
#else
#define VERSION_AS_STRING "1.0.0"
#endif
@ -89,11 +89,11 @@ BEGIN
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", "com.example" "\0"
VALUE "CompanyName", "com.iconica" "\0"
VALUE "FileDescription", "example" "\0"
VALUE "FileVersion", VERSION_AS_STRING "\0"
VALUE "InternalName", "example" "\0"
VALUE "LegalCopyright", "Copyright (C) 2022 com.example. All rights reserved." "\0"
VALUE "LegalCopyright", "Copyright (C) 2022 com.iconica. All rights reserved." "\0"
VALUE "OriginalFilename", "example.exe" "\0"
VALUE "ProductName", "example" "\0"
VALUE "ProductVersion", VERSION_AS_STRING "\0"

View file

@ -7,7 +7,7 @@
</application>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<!-- Windows 10 and Windows 11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>

View file

@ -2,3 +2,8 @@ library flutter_date_time_picker;
export 'src/date_time_picker.dart';
export 'src/enums/date_box_shape.dart';
export 'src/models/date_box_base_theme.dart';
export 'src/models/date_box_disabled_theme.dart';
export 'src/models/date_box_highlight_theme.dart';
export 'src/models/date_box_selected_theme.dart';
export 'src/models/date_time_picker_theme.dart';

View file

@ -1,7 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/src/enums/date_box_shape.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_controller.dart';
import 'package:flutter_date_time_picker/src/widgets/month_date_time_picker.dart/month_date_time_picker_sheet.dart';
import 'package:flutter_date_time_picker/src/widgets/week_date_time_picker/week_date_time_picker_sheet.dart';
@ -9,27 +9,42 @@ import 'package:intl/date_symbol_data_local.dart';
/// A widget that displays a date picker from a sheet form the top of the screen.
/// This sheet displays initialy displays a week of days but can be dragged down to show full months.
/// Both views can be dragged sideways to show the next or previous wweek/month.
/// Both views can be dragged sideways to show the next or previous week/month.
///
/// The child will be the [Widget] that is displayed underneath the date picker in the stack.
///
///
/// [initialDate] indicates the starting date. Default is [DateTime.now()
///
/// [pickTime] is a [bool] that determines if the user is able to pick a time after picking a date.
/// true will always tirgger a [TimePickerDialog].
/// false will nvever trigger a [TimePickerDialog]. This is default.
///
/// [use24HourFormat] is a [bool] to set de clock on [TimePickerDialog] to a fixed 24 or 12-hour format.
/// By default this gets determined by the [Locale] on the device.
///
/// [dateTimePickerTheme] is used the set the global theme of the [DateTimePicker]
///
/// The header [Widget] will be displayed above the date picker in the modal sheet in a column.
///
/// onTapDay is a callback that provides the taped date as a [DateTime] object.
/// [onTapDay] is a callback that provides the taped date as a [DateTime] object.
///
/// highlightToday is a [bool] that determines which day shall we highlighted.
/// [highlightToday] is a [bool] that determines which day shall we highlighted.
/// true will always highlight the current date. This is standard.
/// false will highlight the currently selected date by either the initial date or the one chosen by the user.
/// [highlighColor] is used as background for the highlighted day.
/// [toggleableActiveColor] is used for the text color when highlighted.
/// [disabledColor] is used for the text color when not highlighted.
/// final Widget? child;
///
/// [markedDates] contain the dates [DateTime] that will be marked in the picker by a small dot.
///
/// [disabledDates] contain the dates [DateTime] that will be disabled and cannot be interacted with whatsoever.
///
/// [disabledTimes] contain the time [TimeOfDay] that cannot be picked in the [TimePickerDialog].
///
/// markedDates contain the dates [DateTime] that will be marked in the picker by a small dot.
/// [indicatorColor] is used for the color of the dot.
///
/// Example:
/// ```dart
/// ShellDatePicker(
/// DatePicker(
/// dateTimePickerTheme: const DateTimePickerTheme()
/// initialDate: selectedDate,
/// highlightToday: false,
/// onTapDay: (date) {
@ -112,35 +127,29 @@ import 'package:intl/date_symbol_data_local.dart';
///```
class DateTimePicker extends StatefulWidget {
DateTimePicker({
required this.child,
this.weekDateBoxSize = 35,
this.monthDateBoxSize = 45,
this.dateTimePickerTheme = const DateTimePickerTheme(),
this.header,
this.onTapDay,
this.highlightToday = true,
bool? use24HourFormat,
this.pickTime = false,
this.dateBoxSize,
this.dateBoxShape = DateBoxShape.roundedRectangle,
this.initialDate,
this.markedDates,
this.disabledDates,
this.disabledTimes,
this.child,
super.key,
}) {
alwaysUse24HourFormat = use24HourFormat ?? useTimeFormatBasedOnLocale();
}
final Widget child;
final Widget? child;
final DateTimePickerTheme dateTimePickerTheme;
final Widget? header;
final Function(DateTime)? onTapDay;
final bool highlightToday;
late final bool alwaysUse24HourFormat;
final bool pickTime;
final double? dateBoxSize;
final DateBoxShape dateBoxShape;
final double weekDateBoxSize;
final double monthDateBoxSize;
final DateTime? initialDate;
final List<DateTime>? markedDates;
final List<DateTime>? disabledDates;
@ -165,7 +174,7 @@ class _DateTimePickerState extends State<DateTimePicker> {
highlightToday: widget.highlightToday,
alwaysUse24HourFormat: widget.alwaysUse24HourFormat,
pickTime: widget.pickTime,
dateBoxShape: widget.dateBoxShape,
theme: widget.dateTimePickerTheme,
header: widget.header,
markedDates: widget.markedDates,
disabledDates: widget.disabledDates,
@ -176,8 +185,6 @@ class _DateTimePickerState extends State<DateTimePicker> {
);
_dateTimePickerController.addListener(() {
print('BROWSING DATE: ${_dateTimePickerController.browsingDate}');
print('SELECTED DATE: ${_dateTimePickerController.selectedDate}');
setState(() {});
});
}
@ -193,7 +200,9 @@ class _DateTimePickerState extends State<DateTimePicker> {
Widget build(BuildContext context) {
return Stack(
children: [
widget.child,
if (widget.child != null) ...[
widget.child!,
],
RotatedBox(
quarterTurns: 2,
child: DraggableScrollableSheet(
@ -201,7 +210,7 @@ class _DateTimePickerState extends State<DateTimePicker> {
snap: true,
minChildSize: 0.2,
initialChildSize: 0.2,
maxChildSize: 0.68,
maxChildSize: 0.6,
builder: (context, scrollController) {
double dragSize =
_dragController.isAttached ? _dragController.size : 0;
@ -233,12 +242,14 @@ class _DateTimePickerState extends State<DateTimePicker> {
? WeekDateTimePickerSheet(
dateTimePickerController:
_dateTimePickerController,
weekDateBoxSize: widget.weekDateBoxSize,
weekDateBoxSize: widget
.dateTimePickerTheme.weekDateBoxSize,
)
: MonthDateTimePickerSheet(
dateTimePickerController:
_dateTimePickerController,
monthDateBoxSize: widget.monthDateBoxSize,
monthDateBoxSize: widget
.dateTimePickerTheme.monthDateBoxSize,
),
),
),

View file

@ -0,0 +1,15 @@
import 'package:flutter/widgets.dart' show Color, TextStyle;
class DateBoxBaseTheme {
/// Default date theme.
const DateBoxBaseTheme(
this.backgroundColor,
this.textStyle,
);
/// Background color of default date
final Color? backgroundColor;
/// The style of the date number.
final TextStyle? textStyle;
}

View file

@ -0,0 +1,15 @@
import 'package:flutter/widgets.dart' show Color, TextStyle;
class DateBoxCurrentTheme {
/// Default date theme.
const DateBoxCurrentTheme(
this.backgroundColor,
this.textStyle,
);
/// Background color of default date
final Color backgroundColor;
/// The style of the date number.
final TextStyle textStyle;
}

View file

@ -0,0 +1,15 @@
import 'package:flutter/widgets.dart' show Color, TextStyle;
class DateBoxDisabledTheme {
/// Disabled date theme.
const DateBoxDisabledTheme(
this.backgroundColor,
this.textStyle,
);
/// Background color of selected date.
final Color? backgroundColor;
/// The style of the date number.
final TextStyle? textStyle;
}

View file

@ -0,0 +1,15 @@
import 'package:flutter/widgets.dart' show Color, TextStyle;
class DateBoxHighlightTheme {
/// Highlighted date theme.
const DateBoxHighlightTheme(
this.backgroundColor,
this.textStyle,
);
/// Background color of highlighted date.
final Color? backgroundColor;
/// The style of the date number.
final TextStyle? textStyle;
}

View file

@ -0,0 +1,15 @@
import 'package:flutter/widgets.dart' show Color, TextStyle;
class DateBoxSelectedTheme {
/// Selected date theme.
const DateBoxSelectedTheme(
this.backgroundColor,
this.textStyle,
);
/// Background color of selected date.
final Color? backgroundColor;
/// The style of the date number.
final TextStyle? textStyle;
}

View file

@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/flutter_date_time_picker.dart';
import 'package:flutter_date_time_picker/src/models/date_box_base_theme.dart';
import 'package:flutter_date_time_picker/src/models/date_box_disabled_theme.dart';
import 'package:flutter_date_time_picker/src/models/date_box_highlight_theme.dart';
import 'package:flutter_date_time_picker/src/models/date_box_selected_theme.dart';
class DateTimePickerTheme {
/// The [DateTimePickerTheme] to style [DateTimePicker] in. Define a custom shape for the dates and specifically style
/// a basic, hightlighted, selected and disabled date.
const DateTimePickerTheme({
this.weekDateBoxSize = 35,
this.monthDateBoxSize = 45,
this.markedIndicatorColor,
this.dateBoxShape = DateBoxShape.roundedRectangle,
this.baseTheme = const DateBoxBaseTheme(
Colors.white,
TextStyle(color: Colors.black),
),
this.highlightTheme = const DateBoxHighlightTheme(
Colors.blue,
TextStyle(color: Colors.white),
),
this.selectedTheme = const DateBoxSelectedTheme(
Color(0xFFBBDEFB),
TextStyle(color: Colors.blue),
),
this.disabledTheme = const DateBoxDisabledTheme(
Colors.grey,
TextStyle(color: Colors.white),
),
});
/// enum to define a shape dor the date. use [DateBoxShape.circle].
/// For a ciruclar date, [DateBoxShape.rectangle] for a plain box and [DateBoxShape.roundedRectangle] to het a rectangle with small rounded borders.
final DateBoxShape dateBoxShape;
/// This theme is used to style a default look for the dates.
final DateBoxBaseTheme baseTheme;
/// This theme is used for when a specific date is highlighted.
final DateBoxHighlightTheme highlightTheme;
/// This theme is used for when a specific date is slected by the user.
final DateBoxSelectedTheme selectedTheme;
/// This theme is used for when a specific date is disabled.
final DateBoxDisabledTheme disabledTheme;
/// Size of date box in a week view.
final double weekDateBoxSize;
/// Size of date box in a month view.
final double monthDateBoxSize;
/// The color used for a indicator for a marked date.
final Color? markedIndicatorColor;
}

View file

@ -1,23 +1,21 @@
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/src/enums/date_box_shape.dart';
import 'package:flutter_date_time_picker/src/models/date_time_picker_theme.dart';
class DateTimePickerController extends ChangeNotifier {
DateTimePickerController({
required this.theme,
required this.highlightToday,
required this.alwaysUse24HourFormat,
required this.pickTime,
required this.dateBoxShape,
required this.browsingDate,
required this.selectedDate,
this.header,
this.markedDates,
this.disabledDates,
this.disabledTimes,
this.onTapDayCallBack,
required this.browsingDate,
required this.selectedDate,
});
final PageController _pageController = PageController(initialPage: 1);
final bool highlightToday;
@ -25,7 +23,7 @@ class DateTimePickerController extends ChangeNotifier {
final Widget? header;
final DateBoxShape dateBoxShape;
final DateTimePickerTheme theme;
final List<DateTime>? markedDates;
final List<DateTime>? disabledDates;
@ -56,7 +54,7 @@ class DateTimePickerController extends ChangeNotifier {
);
}
void onTapDay(date) {
void onTapDay(DateTime date) {
browsingDate = date;
selectedDate = date;
@ -69,9 +67,7 @@ class DateTimePickerController extends ChangeNotifier {
}
}
PageController getPageController() {
return _pageController;
}
PageController get pageController => _pageController;
void setBrowsingDate(DateTime date) {
browsingDate = date;

View file

@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/src/enums/date_box_shape.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/models/date_time_picker_theme.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
class MonthDateTimePicker extends StatelessWidget {
@ -37,7 +39,7 @@ class MonthDateTimePicker extends StatelessWidget {
DateTime(date.year, date.month).daysInMonth() +
(daysToSkip >= 7 ? 0 : daysToSkip),
(index) {
late Map<String, Color> calendarColors;
late DateBoxCurrentTheme currentDateBoxTheme;
int addedIndex = index;
@ -48,11 +50,8 @@ class MonthDateTimePicker extends StatelessWidget {
return const SizedBox.shrink();
}
calendarColors = determineColors(
context,
addedIndex,
daysToSkip,
);
currentDateBoxTheme = determineCurrentDateBoxTheme(context,
addedIndex, daysToSkip, dateTimePickerController.theme);
return GestureDetector(
onTap: isDisabled(
@ -76,6 +75,8 @@ class MonthDateTimePicker extends StatelessWidget {
addedIndex + 1 - daysToSkip,
);
timeOfDay = const TimeOfDay(hour: 0, minute: 0);
if (dateTimePickerController.pickTime) {
timeOfDay = await displayTimePicker(
context, dateTimePickerController);
@ -84,15 +85,35 @@ class MonthDateTimePicker extends StatelessWidget {
if (timeOfDay != null &&
timeOfDay.timeContainedIn(
dateTimePickerController.disabledTimes ?? [])) {
} else {
timeOfDay = const TimeOfDay(hour: 0, minute: 0);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Verkeerde tijd gekozen'),
content: SingleChildScrollView(
child: ListBody(
children: const <Widget>[
Text(
'De tijd die u wilt kiezen, is niet mogelijk, maak een andere keuze.'),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.pop(context);
},
),
],
),
);
}
DateTime selectedDateTime = DateTime(
selectedDate.year,
selectedDate.month,
selectedDate.day,
timeOfDay.hour,
timeOfDay!.hour,
timeOfDay.minute,
);
@ -102,7 +123,7 @@ class MonthDateTimePicker extends StatelessWidget {
margin:
const EdgeInsets.symmetric(vertical: 5, horizontal: 5),
decoration: BoxDecoration(
color: calendarColors['backgroundColor'],
color: currentDateBoxTheme.backgroundColor,
borderRadius:
_determineBorderRadius(dateTimePickerController),
),
@ -111,13 +132,8 @@ class MonthDateTimePicker extends StatelessWidget {
child: Stack(
children: [
Center(
child: Text(
(addedIndex + 1 - daysToSkip).toString(),
style:
Theme.of(context).textTheme.bodyText1!.copyWith(
color: calendarColors['textColor'],
),
),
child: Text((addedIndex + 1 - daysToSkip).toString(),
style: currentDateBoxTheme.textStyle),
),
if (shouldMark(
addedIndex,
@ -161,32 +177,39 @@ class MonthDateTimePicker extends StatelessWidget {
);
}
determineColors(context, index, daysToSkip) {
Map<String, Color> calendarColors = {
'backgroundColor': Colors.transparent,
'textColor': Colors.black
};
DateBoxCurrentTheme determineCurrentDateBoxTheme(
BuildContext context,
int index,
int daysToSkip,
DateTimePickerTheme theme,
) {
DateBoxCurrentTheme determinedTheme = DateBoxCurrentTheme(
theme.baseTheme.backgroundColor ?? Colors.transparent,
theme.baseTheme.textStyle ?? const TextStyle(color: Colors.black),
);
if (isDisabled(index, daysToSkip)) {
calendarColors = {
'backgroundColor': Theme.of(context).disabledColor,
'textColor': Colors.white
};
determinedTheme = DateBoxCurrentTheme(
theme.disabledTheme.backgroundColor ?? Theme.of(context).disabledColor,
theme.disabledTheme.textStyle ?? const TextStyle(color: Colors.white),
);
}
if (isSelected(index, daysToSkip)) {
calendarColors = {
'backgroundColor': Theme.of(context).primaryColor.withOpacity(0.3),
'textColor': Theme.of(context).primaryColor
};
determinedTheme = DateBoxCurrentTheme(
theme.selectedTheme.backgroundColor ??
Theme.of(context).primaryColor.withOpacity(0.3),
theme.selectedTheme.textStyle ??
TextStyle(color: Theme.of(context).primaryColor));
}
if (shouldHighlight(index, daysToSkip)) {
calendarColors = {
'backgroundColor': Theme.of(context).primaryColor,
'textColor': Colors.white
};
determinedTheme = DateBoxCurrentTheme(
theme.highlightTheme.backgroundColor ??
Theme.of(context).primaryColor,
theme.highlightTheme.textStyle ??
const TextStyle(color: Colors.white));
}
return calendarColors;
return determinedTheme;
}
bool isDisabled(int index, int daysToSkip) {
@ -228,7 +251,7 @@ class MonthDateTimePicker extends StatelessWidget {
BorderRadius _determineBorderRadius(
DateTimePickerController dateTimePickerController) {
switch (dateTimePickerController.dateBoxShape) {
switch (dateTimePickerController.theme.dateBoxShape) {
case DateBoxShape.circle:
return BorderRadius.circular(monthDateBoxSize * 2);
case DateBoxShape.rectangle:
@ -239,39 +262,9 @@ class MonthDateTimePicker extends StatelessWidget {
}
}
class WrongTimeDialog extends StatelessWidget {
const WrongTimeDialog({required this.dateTimePickerController, Key? key})
: super(key: key);
final DateTimePickerController dateTimePickerController;
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Verkeerde tijd gekozen'),
content: SingleChildScrollView(
child: ListBody(
children: const <Widget>[
Text(
'De tijd die u wilt kiezen, is niet mogelijk, maak een andere keuze.'),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('OK'),
onPressed: () {
displayTimePicker(context, dateTimePickerController);
},
),
],
);
}
}
displayTimePicker(BuildContext context,
DateTimePickerController dateTimePickerController) async {
await showTimePicker(
return await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
builder: (BuildContext context, Widget? child) {

View file

@ -39,7 +39,7 @@ class MonthDateTimePickerSheet extends StatelessWidget {
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.33,
child: PageView(
controller: dateTimePickerController.getPageController(),
controller: dateTimePickerController.pageController,
onPageChanged: (i) {
if (i == 0) {
dateTimePickerController.onPageChanged(

View file

@ -2,6 +2,8 @@ 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/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_controller.dart';
import 'package:intl/intl.dart';
@ -26,12 +28,10 @@ class WeekDateTimePicker extends StatelessWidget {
children: List.generate(
date.daysOfWeek().length,
(index) {
late Map<String, Color> calendarColors;
late DateBoxCurrentTheme currentDateBoxTheme;
calendarColors = determineColors(
context,
index,
);
currentDateBoxTheme = determineCurrentDateBoxTheme(
context, index, dateTimePickerController.theme);
return GestureDetector(
onTap: isDisabled(
index,
@ -50,18 +50,8 @@ class WeekDateTimePicker extends StatelessWidget {
DateTime selectedDate = date.daysOfWeek()[index];
if (dateTimePickerController.pickTime) {
timeOfDay = await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
builder: (BuildContext context, Widget? child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
alwaysUse24HourFormat:
dateTimePickerController
.alwaysUse24HourFormat),
child: child!,
);
});
timeOfDay = await displayTimePicker(
context, dateTimePickerController);
}
if (timeOfDay != null &&
@ -76,7 +66,7 @@ class WeekDateTimePicker extends StatelessWidget {
child: ListBody(
children: const <Widget>[
Text(
'De tijd die u wilt kiezen, is niet mogelijk, makke een andere keuze.'),
'De tijd die u wilt kiezen, is niet mogelijk, maak een andere keuze.'),
],
),
),
@ -84,14 +74,14 @@ class WeekDateTimePicker extends StatelessWidget {
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
Navigator.pop(context);
},
),
],
);
});
} else {
timeOfDay = TimeOfDay(
timeOfDay = const TimeOfDay(
hour: 0,
minute: 0,
);
@ -126,7 +116,7 @@ class WeekDateTimePicker extends StatelessWidget {
height: weekDateBoxSize,
width: weekDateBoxSize,
decoration: BoxDecoration(
color: calendarColors['backgroundColor'],
color: currentDateBoxTheme.backgroundColor,
borderRadius:
_determineBorderRadius(dateTimePickerController),
),
@ -135,10 +125,7 @@ class WeekDateTimePicker extends StatelessWidget {
Center(
child: Text(
date.daysOfWeek().elementAt(index).day.toString(),
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: calendarColors['textColor']),
style: currentDateBoxTheme.textStyle,
),
),
if (shouldMark(index)) ...[
@ -148,7 +135,9 @@ class WeekDateTimePicker extends StatelessWidget {
width: weekDateBoxSize / 3,
height: weekDateBoxSize / 3,
decoration: BoxDecoration(
color: Theme.of(context).indicatorColor,
color: dateTimePickerController
.theme.markedIndicatorColor ??
Theme.of(context).indicatorColor,
borderRadius:
BorderRadius.circular(weekDateBoxSize * 2),
),
@ -168,32 +157,38 @@ class WeekDateTimePicker extends StatelessWidget {
);
}
determineColors(context, index) {
Map<String, Color> calendarColors = {
'backgroundColor': Colors.transparent,
'textColor': Colors.black
};
DateBoxCurrentTheme determineCurrentDateBoxTheme(
BuildContext context,
int index,
DateTimePickerTheme theme,
) {
DateBoxCurrentTheme determinedTheme = DateBoxCurrentTheme(
theme.baseTheme.backgroundColor ?? Colors.transparent,
theme.baseTheme.textStyle ?? const TextStyle(color: Colors.black),
);
if (isDisabled(index)) {
calendarColors = {
'backgroundColor': Theme.of(context).disabledColor,
'textColor': Colors.white
};
determinedTheme = DateBoxCurrentTheme(
theme.disabledTheme.backgroundColor ?? Theme.of(context).disabledColor,
theme.disabledTheme.textStyle ?? const TextStyle(color: Colors.white),
);
}
if (isSelected(index)) {
calendarColors = {
'backgroundColor': Theme.of(context).primaryColor.withOpacity(0.3),
'textColor': Theme.of(context).primaryColor
};
determinedTheme = DateBoxCurrentTheme(
theme.selectedTheme.backgroundColor ??
Theme.of(context).primaryColor.withOpacity(0.3),
theme.selectedTheme.textStyle ??
TextStyle(color: Theme.of(context).primaryColor));
}
if (shouldHighlight(index)) {
calendarColors = {
'backgroundColor': Theme.of(context).primaryColor,
'textColor': Colors.white
};
determinedTheme = DateBoxCurrentTheme(
theme.highlightTheme.backgroundColor ??
Theme.of(context).primaryColor,
theme.highlightTheme.textStyle ??
const TextStyle(color: Colors.white));
}
return calendarColors;
return determinedTheme;
}
bool shouldHighlight(int index) {
@ -232,7 +227,7 @@ class WeekDateTimePicker extends StatelessWidget {
BorderRadius _determineBorderRadius(
DateTimePickerController dateTimePickerController) {
switch (dateTimePickerController.dateBoxShape) {
switch (dateTimePickerController.theme.dateBoxShape) {
case DateBoxShape.circle:
return BorderRadius.circular(weekDateBoxSize * 2);
case DateBoxShape.rectangle:
@ -241,4 +236,19 @@ class WeekDateTimePicker extends StatelessWidget {
return BorderRadius.circular(weekDateBoxSize / 4.5);
}
}
displayTimePicker(BuildContext context,
DateTimePickerController dateTimePickerController) async {
return await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
builder: (BuildContext context, Widget? child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
alwaysUse24HourFormat:
dateTimePickerController.alwaysUse24HourFormat),
child: child!,
);
});
}
}

View file

@ -55,7 +55,7 @@ class WeekDateTimePickerSheet extends StatelessWidget {
width: MediaQuery.of(context).size.width,
height: 60,
child: PageView(
controller: dateTimePickerController.getPageController(),
controller: dateTimePickerController.pageController,
onPageChanged: (i) {
if (i == 0) {
dateTimePickerController.onPageChanged(

View file

@ -1,12 +1,17 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_date_time_picker/flutter_date_time_picker.dart';
void main() {
test('adds one to input values', () {
final calculator = Calculator();
expect(calculator.addOne(2), 3);
expect(calculator.addOne(-7), -6);
expect(calculator.addOne(0), 1);
testWidgets('MyWidget has a title and message', (tester) async {
// Create the widget by telling the tester to build it.
await tester.pumpWidget(Scaffold(
appBar: AppBar(),
body: DateTimePicker(
pickTime: false,
child: Container(),
),
));
});
}