/
date_range_picker.dart
156 lines (151 loc) · 5.52 KB
/
date_range_picker.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import 'package:digit_components/digit_components.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
class DateRangePicker extends StatelessWidget {
final DateFormat? format;
final String label;
final String? applyLabel;
final String? cancelLabel;
final TextEditingController controller;
final DateRangePickerController rangePickerController;
final DateRangePickerSelectionMode selectionMode;
final void Function(DateRangePickerSelectionChangedArgs)? onChangeOfDate;
final void Function(DateRangePickerViewChangedArgs)? onViewChange;
final void Function()? onSubmit;
final void Function()? onCancel;
final DateTime? minDate;
final DateTime? maxDate;
DateRangePicker(
{Key? key,
required this.label,
required this.controller,
required this.rangePickerController,
required this.selectionMode,
this.onChangeOfDate,
this.onViewChange,
this.onSubmit,
this.applyLabel,
this.cancelLabel,
this.onCancel,
this.minDate,
this.maxDate,
this.format,})
: super(key: key);
@override
Widget build(BuildContext context) {
Widget datePicker(BuildContext dialogContext) {
return SafeArea(
child: Column(
children: [
Expanded(
child: SfDateRangePicker(
viewSpacing: 30,
onSelectionChanged: onChangeOfDate,
controller: rangePickerController,
selectionMode: selectionMode,
selectionRadius: 30,
onViewChanged: onViewChange,
minDate: minDate,
maxDate: maxDate,
startRangeSelectionColor:
DigitTheme.instance.colorScheme.secondary,
endRangeSelectionColor:
DigitTheme.instance.colorScheme.secondary,
selectionColor: Theme.of(context).hintColor,
monthViewSettings: const DateRangePickerMonthViewSettings(
enableSwipeSelection: false,
firstDayOfWeek: 1,
dayFormat: 'EEE'))),
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
TextButton(
onPressed: () {
onCancel!();
Navigator.pop(dialogContext);
},
child: Text(cancelLabel ?? ''),
),
DigitElevatedButton(
onPressed: () {
onSubmit!();
Navigator.pop(dialogContext);
},
child: Text(applyLabel ?? 'Apply'),
),
],
),
],
),
);
}
Widget getDateRangePicker(BuildContext dialogContext) {
return SizedBox(
height: 250, child: Card(child: datePicker(dialogContext)));
}
if (MediaQuery.of(context).size.width < 760) {
return Container(
margin: const EdgeInsets.only(top: 5.0, bottom: 5, right: 8, left: 8),
child: Column(children: [
DigitTextField(
label: label,
readOnly: true,
controller: controller,
suffixIcon: IconButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext dialogContext) {
return Dialog(
child: SizedBox(
height: 350,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
getDateRangePicker(dialogContext),
],
),
));
});
},
icon: const Icon(
Icons.date_range,
size: 24,
))),
]));
} else {
return Container(
margin:
const EdgeInsets.only(top: 20.0, bottom: 5, right: 20, left: 20),
child: Row(children: [
SizedBox(
width: MediaQuery.of(context).size.width / 2,
child: DigitTextField(
label: label,
readOnly: true,
controller: controller,
suffixIcon: IconButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext dialogContext) {
return Dialog(
child: SizedBox(
height: 350,
child: Column(
children: <Widget>[
getDateRangePicker(dialogContext),
],
),
));
});
},
icon: const Icon(
Icons.date_range,
)))),
]));
}
}
}