mirror of
https://github.com/Iconica-Development/flutter_date_time_picker.git
synced 2025-05-18 18:33:49 +02:00
feat: Controller now has to be provided as parameter so the selected date can be changed from outside the widget.
This commit is contained in:
parent
55ec65d59e
commit
61e2b849fa
12 changed files with 95 additions and 102 deletions
|
@ -1,3 +1,7 @@
|
|||
## 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
|
||||
|
|
|
@ -156,8 +156,12 @@ class DatePickerDemo extends StatelessWidget {
|
|||
),
|
||||
DragDownDateTimePicker(
|
||||
onTimerPickerSheetChange: (value) {},
|
||||
controller: DateTimePickerController(
|
||||
initialDate: DateTime.now(),
|
||||
highlightToday: true,
|
||||
alwaysUse24HourFormat: true,
|
||||
dateTimePickerTheme: const DateTimePickerTheme(
|
||||
markedDates: [DateTime.now().subtract(const Duration(days: 1))],
|
||||
theme: const DateTimePickerTheme(
|
||||
backgroundColor: Colors.white,
|
||||
markedIndicatorColor: Colors.red,
|
||||
baseTheme: DateBoxTheme(
|
||||
|
@ -181,7 +185,7 @@ class DatePickerDemo extends StatelessWidget {
|
|||
barOpacity: 1,
|
||||
),
|
||||
),
|
||||
markedDates: [DateTime.now().subtract(const Duration(days: 1))],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -68,7 +68,7 @@ packages:
|
|||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "3.3.2"
|
||||
version: "3.3.3"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
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/overlay_date_time_picker.dart' show OverlayDateTimePicker;
|
||||
export 'src/models/date_constraint.dart';
|
||||
export 'src/enums/date_box_shape.dart';
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// 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_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 +15,21 @@ 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,
|
||||
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;
|
||||
|
||||
/// 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 +39,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 +50,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(() {});
|
||||
});
|
||||
|
@ -166,16 +115,16 @@ class _DragDownDateTimePickerState extends State<DragDownDateTimePicker> {
|
|||
? WeekDateTimePickerSheet(
|
||||
dateTimePickerController:
|
||||
_dateTimePickerController,
|
||||
weekDateBoxSize: widget
|
||||
.dateTimePickerTheme.weekDateBoxSize,
|
||||
weekDateBoxSize:
|
||||
widget.controller.theme.weekDateBoxSize,
|
||||
)
|
||||
: MonthDateTimePickerSheet(
|
||||
dateTimePickerController:
|
||||
_dateTimePickerController,
|
||||
monthDateBoxSize: widget
|
||||
.dateTimePickerTheme.monthDateBoxSize,
|
||||
monthDatePadding: widget
|
||||
.dateTimePickerTheme.monthDatePadding,
|
||||
monthDateBoxSize:
|
||||
widget.controller.theme.monthDateBoxSize,
|
||||
monthDatePadding:
|
||||
widget.controller.theme.monthDatePadding,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -127,8 +127,7 @@ class _OverlayDateTimePickerState extends State<OverlayDateTimePicker> {
|
|||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
browsingDate: widget.initialDate ?? DateTime.now(),
|
||||
selectedDate: widget.initialDate ?? DateTime.now(),
|
||||
initialDate: widget.initialDate ?? DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,8 @@ class DateTimePickerController extends ChangeNotifier {
|
|||
DateTimePickerController({
|
||||
required this.theme,
|
||||
required this.highlightToday,
|
||||
required this.pickTime,
|
||||
required this.browsingDate,
|
||||
required this.selectedDate,
|
||||
required this.initialDate,
|
||||
this.pickTime = false,
|
||||
this.alwaysUse24HourFormat,
|
||||
this.header,
|
||||
this.wrongTimeDialog,
|
||||
|
@ -19,28 +18,48 @@ class DateTimePickerController extends ChangeNotifier {
|
|||
this.disabledDates,
|
||||
this.disabledTimes,
|
||||
this.onTapDayCallBack,
|
||||
this.onBorderScrollCallback,
|
||||
});
|
||||
|
||||
final PageController _pageController = PageController(initialPage: 1);
|
||||
|
||||
/// 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;
|
||||
|
||||
/// Callback that provides the date tapped on as a [DateTime] object.
|
||||
final Function(DateTime)? onTapDayCallBack;
|
||||
|
||||
DateTime browsingDate;
|
||||
DateTime selectedDate;
|
||||
/// Callback that provides the new date which is scroll to. If this is null the scroll feature is disabled.
|
||||
final Function(DateTime)? onBorderScrollCallback;
|
||||
|
||||
final DateTime initialDate;
|
||||
|
||||
final PageController _pageController = PageController(initialPage: 1);
|
||||
|
||||
late DateTime browsingDate = initialDate;
|
||||
late DateTime selectedDate = initialDate;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
|
@ -74,6 +93,17 @@ class DateTimePickerController extends ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
void onBorderScroll(DateTime date) {
|
||||
browsingDate = date;
|
||||
selectedDate = date;
|
||||
|
||||
notifyListeners();
|
||||
|
||||
onBorderScrollCallback?.call(
|
||||
date,
|
||||
);
|
||||
}
|
||||
|
||||
PageController get pageController => _pageController;
|
||||
|
||||
void setBrowsingDate(DateTime date) {
|
||||
|
|
|
@ -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 {
|
||||
|
@ -105,8 +104,7 @@ class _DateTimePickerState extends State<DateTimePicker> {
|
|||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
browsingDate: widget.initialDate ?? DateTime.now(),
|
||||
selectedDate: widget.initialDate ?? DateTime.now(),
|
||||
initialDate: widget.initialDate ?? DateTime.now(),
|
||||
);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
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';
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ 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';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_date_time_picker
|
||||
description: A Flutter package for date and time picker.
|
||||
version: 3.3.3
|
||||
version: 4.0.0
|
||||
|
||||
environment:
|
||||
sdk: ">=3.0.0 <4.0.0"
|
||||
|
|
|
@ -13,7 +13,12 @@ void main() {
|
|||
home: Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: DragDownDateTimePicker(
|
||||
controller: DateTimePickerController(
|
||||
theme: const DateTimePickerTheme(),
|
||||
highlightToday: true,
|
||||
initialDate: DateTime.now(),
|
||||
pickTime: false,
|
||||
),
|
||||
child: Container(),
|
||||
),
|
||||
),
|
||||
|
@ -27,7 +32,12 @@ void main() {
|
|||
home: Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: DragDownDateTimePicker(
|
||||
controller: DateTimePickerController(
|
||||
theme: const DateTimePickerTheme(),
|
||||
highlightToday: true,
|
||||
initialDate: DateTime.now(),
|
||||
pickTime: false,
|
||||
),
|
||||
child: Container(),
|
||||
),
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue