Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
calender_date_picker_view.dart
Go to the documentation of this file.
1import 'package:connect/core/localization/app_localizations.dart';
2
3import '/core/ui/widgets/custom_action_slider.dart';
4import '/core/ui/widgets/custom_snackbar.dart';
5import 'package:flutter/material.dart';
6import 'package:flutter_screenutil/flutter_screenutil.dart';
7import 'package:syncfusion_flutter_datepicker/datepicker.dart';
8
9class CalendarView extends StatefulWidget {
11 super.key,
12 required this.selectedDates,
13 this.startDate,
14 this.endDate,
15 });
16
17 final DateTime? startDate;
18 final DateTime? endDate;
19 final Function(DateTime? startDate, DateTime? endDate) selectedDates;
20
21 @override
22 State<CalendarView> createState() => _CalendarViewState();
23}
24
25class _CalendarViewState extends State<CalendarView> {
26 DateTime? startDate;
27 DateTime? endDate;
28
29 @override
30 void initState() {
31 startDate = widget.startDate;
32 endDate = widget.endDate;
33 super.initState();
34 }
35
36 @override
37 Widget build(BuildContext context) {
38 return Container(
39 decoration: BoxDecoration(
40 gradient: LinearGradient(
41 begin: Alignment.topCenter,
42 end: Alignment.center,
43 colors: [
44 Theme.of(context).colorScheme.surface.withOpacity(0.5),
45 Theme.of(context).scaffoldBackgroundColor,
46 ],
47 ),
48 ),
49 padding: EdgeInsets.symmetric(
50 horizontal: 25.sp,
51 vertical: 20.sp,
52 ),
53 child: Column(
54 mainAxisSize: MainAxisSize.min,
55 children: [
56 SfDateRangePicker(
57 headerHeight: 40.sp,
58 headerStyle: DateRangePickerHeaderStyle(
59 backgroundColor: Colors.transparent,
60 textStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
61 color: Theme.of(context).colorScheme.primary,
62 ),
63 ),
64 monthCellStyle: DateRangePickerMonthCellStyle(
65 textStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
66 // color: Theme.of(context)..withOpacity(0.7),
67 ),
68 ),
69 selectionTextStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
70 color: Theme.of(context).colorScheme.onPrimary,
71 fontSize: 10.sp,
72 fontWeight: FontWeight.bold,
73 ),
74 monthViewSettings: DateRangePickerMonthViewSettings(
75 viewHeaderStyle: DateRangePickerViewHeaderStyle(
76 textStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
77 // color: ColorPalette.black.withOpacity(0.5),
78 ),
79 ),
80 weekNumberStyle: DateRangePickerWeekNumberStyle(
81 textStyle: Theme.of(context).textTheme.bodySmall?.copyWith(),
82 ),
83 ),
84 todayHighlightColor: Theme.of(context).colorScheme.primary,
85 showTodayButton: false,
86 onSelectionChanged: _onSelectionChanged,
87 initialDisplayDate: widget.startDate,
88 selectionMode: DateRangePickerSelectionMode.range,
89 initialSelectedRange: PickerDateRange(
90 widget.startDate,
91 widget.endDate,
92 ),
93 ),
94 SizedBox(height: 15.sp),
95 CustomSliderV2(
96 text: AppLocalizations.of(context).translate('CONFIRM'),
97 action: (action) {
98 widget.selectedDates(startDate, endDate);
99 },
100 ),
101 ],
102 ),
103 );
104 }
105
106 bool validateDates({DateTime? startDate, DateTime? endDate}) {
107 showWarningSnackBar(String message) {
108 CustomSnackBar.display(
109 context,
110 Theme.of(context).hintColor,
111 message,
112 );
113 }
114
115 if (startDate != null && endDate != null) {
116 if (startDate.millisecondsSinceEpoch > endDate.millisecondsSinceEpoch) {
117 showWarningSnackBar(
118 AppLocalizations.of(context)
119 .translate('Start date cannot be greater than end date'),
120 );
121 return false;
122 }
123
124 if (startDate.millisecondsSinceEpoch > endDate.millisecondsSinceEpoch) {
125 showWarningSnackBar(
126 AppLocalizations.of(context)
127 .translate('Start date cannot be greater than end date'),
128 );
129 return false;
130 }
131
132 int differenceInMonths = (endDate.year - startDate.year) * 12 +
133 endDate.month -
134 startDate.month;
135 if (differenceInMonths > 2) {
136 showWarningSnackBar(
137 AppLocalizations.of(context)
138 .translate('Please select a duration less than 3 months'),
139 );
140 return false;
141 }
142 } else {
143 showWarningSnackBar(
144 AppLocalizations.of(context)
145 .translate('Please select both start and end date'),
146 );
147 return false;
148 }
149
150 this.startDate = startDate;
151 this.endDate = endDate;
152
153 return true;
154 }
155
156 void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) {
157 if (args.value is PickerDateRange) {
158 startDate = args.value.startDate;
159 endDate = args.value.endDate;
160 }
161 }
162}
AppLocalizations(this.locale)
DateTime startDate
DateTime endDate
void _onSelectionChanged(DateRangePickerSelectionChangedArgs args)
bool validateDates({DateTime? startDate, DateTime? endDate})
String translate(String key)
static AppLocalizations of(BuildContext context)
const CalendarView({ super.key, required this.selectedDates, this.startDate, this.endDate, })
final Function(DateTime? startDate, DateTime? endDate) selectedDates
override State< CalendarView > createState()
final Widget child
final EdgeInsets padding
override void initState()
final Color backgroundColor
final Color color
Definition failures.dart:1
final String message
Definition failures.dart:0
override Widget build(BuildContext context)