mirror of
https://github.com/Iconica-Development/flutter_form_wizard.git
synced 2025-05-19 19:03:47 +02:00
add initial date params
This commit is contained in:
parent
96158b9e36
commit
d8691d36aa
3 changed files with 37 additions and 6 deletions
|
@ -31,9 +31,15 @@ class _DatePageState extends State<DatePage> {
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(40, 0, 40, 40),
|
padding: const EdgeInsets.fromLTRB(40, 0, 40, 40),
|
||||||
child: FlutterFormInputDateTime(
|
child: FlutterFormInputDateTime(
|
||||||
inputType: FlutterFormDateTimeType.dateTime,
|
inputType: FlutterFormDateTimeType.range,
|
||||||
dateFormat: DateFormat.yMd(),
|
dateFormat: DateFormat.yMd(),
|
||||||
firstDate: DateTime.now(),
|
firstDate: DateTime.now(),
|
||||||
|
initialDateTimeRange: DateTimeRange(
|
||||||
|
start: DateTime.now(),
|
||||||
|
end: DateTime.now().add(
|
||||||
|
const Duration(days: 7),
|
||||||
|
),
|
||||||
|
),
|
||||||
label: const Text("Date"),
|
label: const Text("Date"),
|
||||||
controller: widget.dateController,
|
controller: widget.dateController,
|
||||||
),
|
),
|
||||||
|
|
|
@ -19,6 +19,8 @@ class DateTimeInputField extends ConsumerStatefulWidget {
|
||||||
required this.dateFormat,
|
required this.dateFormat,
|
||||||
required this.firstDate,
|
required this.firstDate,
|
||||||
required this.lastDate,
|
required this.lastDate,
|
||||||
|
this.initialDate,
|
||||||
|
this.initialDateTimeRange,
|
||||||
}) : super(
|
}) : super(
|
||||||
key: key,
|
key: key,
|
||||||
);
|
);
|
||||||
|
@ -28,6 +30,8 @@ class DateTimeInputField extends ConsumerStatefulWidget {
|
||||||
final bool showIcon;
|
final bool showIcon;
|
||||||
final DateTime? firstDate;
|
final DateTime? firstDate;
|
||||||
final DateTime? lastDate;
|
final DateTime? lastDate;
|
||||||
|
final DateTime? initialDate;
|
||||||
|
final DateTimeRange? initialDateTimeRange;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final Widget? label;
|
final Widget? label;
|
||||||
@override
|
@override
|
||||||
|
@ -37,6 +41,8 @@ class DateTimeInputField extends ConsumerStatefulWidget {
|
||||||
class _DateInputFieldState extends ConsumerState<DateTimeInputField> {
|
class _DateInputFieldState extends ConsumerState<DateTimeInputField> {
|
||||||
late final DateTime firstDate;
|
late final DateTime firstDate;
|
||||||
late final DateTime lastDate;
|
late final DateTime lastDate;
|
||||||
|
late final DateTime initialDate;
|
||||||
|
late final DateTimeRange initialDateRange;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -48,6 +54,14 @@ class _DateInputFieldState extends ConsumerState<DateTimeInputField> {
|
||||||
DateTime.now().add(
|
DateTime.now().add(
|
||||||
const Duration(days: 1000),
|
const Duration(days: 1000),
|
||||||
);
|
);
|
||||||
|
initialDate = widget.initialDate ?? DateTime.now();
|
||||||
|
initialDateRange = widget.initialDateTimeRange ??
|
||||||
|
DateTimeRange(
|
||||||
|
start: DateTime.now(),
|
||||||
|
end: DateTime.now().add(
|
||||||
|
const Duration(days: 7),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
@ -62,8 +76,8 @@ class _DateInputFieldState extends ConsumerState<DateTimeInputField> {
|
||||||
switch (inputType) {
|
switch (inputType) {
|
||||||
case FlutterFormDateTimeType.date:
|
case FlutterFormDateTimeType.date:
|
||||||
DateTime? unformatted = await showDatePicker(
|
DateTime? unformatted = await showDatePicker(
|
||||||
|
initialDate: initialDate,
|
||||||
context: context,
|
context: context,
|
||||||
initialDate: DateTime.now(),
|
|
||||||
firstDate: firstDate,
|
firstDate: firstDate,
|
||||||
lastDate: lastDate,
|
lastDate: lastDate,
|
||||||
);
|
);
|
||||||
|
@ -85,10 +99,11 @@ class _DateInputFieldState extends ConsumerState<DateTimeInputField> {
|
||||||
break;
|
break;
|
||||||
case FlutterFormDateTimeType.range:
|
case FlutterFormDateTimeType.range:
|
||||||
userInput = (await showDateRangePicker(
|
userInput = (await showDateRangePicker(
|
||||||
context: context,
|
context: context,
|
||||||
firstDate: firstDate,
|
firstDate: firstDate,
|
||||||
lastDate: lastDate,
|
lastDate: lastDate,
|
||||||
).then((value) {
|
initialDateRange: initialDateRange)
|
||||||
|
.then((value) {
|
||||||
return value != null
|
return value != null
|
||||||
? '${widget.dateFormat.format(value.start)} - ${widget.dateFormat.format(value.end)}'
|
? '${widget.dateFormat.format(value.start)} - ${widget.dateFormat.format(value.end)}'
|
||||||
: '';
|
: '';
|
||||||
|
|
|
@ -27,6 +27,8 @@ class FlutterFormInputDateTime extends FlutterFormInputWidget {
|
||||||
required this.dateFormat,
|
required this.dateFormat,
|
||||||
this.firstDate,
|
this.firstDate,
|
||||||
this.lastDate,
|
this.lastDate,
|
||||||
|
this.initialDate,
|
||||||
|
this.initialDateTimeRange,
|
||||||
this.icon = Icons.calendar_today,
|
this.icon = Icons.calendar_today,
|
||||||
}) : super(
|
}) : super(
|
||||||
key: key,
|
key: key,
|
||||||
|
@ -36,6 +38,8 @@ class FlutterFormInputDateTime extends FlutterFormInputWidget {
|
||||||
final bool showIcon;
|
final bool showIcon;
|
||||||
final FlutterFormDateTimeType inputType;
|
final FlutterFormDateTimeType inputType;
|
||||||
final DateFormat dateFormat;
|
final DateFormat dateFormat;
|
||||||
|
final DateTime? initialDate;
|
||||||
|
final DateTimeRange? initialDateTimeRange;
|
||||||
final DateTime? firstDate;
|
final DateTime? firstDate;
|
||||||
final DateTime? lastDate;
|
final DateTime? lastDate;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
|
@ -52,6 +56,8 @@ class FlutterFormInputDateTime extends FlutterFormInputWidget {
|
||||||
inputType: inputType,
|
inputType: inputType,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
dateFormat: dateFormat,
|
dateFormat: dateFormat,
|
||||||
|
initialDate: initialDate,
|
||||||
|
initialDateTimeRange: initialDateTimeRange,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,11 +73,15 @@ class FlutterFormInputDateTimeController
|
||||||
this.value,
|
this.value,
|
||||||
this.checkPageTitle,
|
this.checkPageTitle,
|
||||||
this.checkPageDescription,
|
this.checkPageDescription,
|
||||||
|
this.initialDate,
|
||||||
|
this.initialDateTimeRange,
|
||||||
required this.dateTimeType,
|
required this.dateTimeType,
|
||||||
required this.dateFormat,
|
required this.dateFormat,
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final DateTime? initialDate;
|
||||||
|
final DateTimeRange? initialDateTimeRange;
|
||||||
final DateFormat dateFormat;
|
final DateFormat dateFormat;
|
||||||
final FlutterFormDateTimeType dateTimeType;
|
final FlutterFormDateTimeType dateTimeType;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue