Skip to content

Commit

Permalink
improve sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Macacoazul01 committed Dec 16, 2024
1 parent ae05cb9 commit f41bade
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
DateTime? selectedDate;
int? selectedYear;
List<DateTime> rangeDates = [];

@override
void initState() {
Expand Down Expand Up @@ -144,8 +145,10 @@ class _MyAppState extends State<MyApp> {
context: contexto,
firstDate: DateTime(DateTime.now().year - 5, 5),
lastDate: DateTime(DateTime.now().year + 8, 9),
initialRangeDate: DateTime(DateTime.now().year - 1, 5),
endRangeDate: DateTime(DateTime.now().year - 1, 7),
initialRangeDate:
rangeDates.firstOrNull ?? DateTime(DateTime.now().year - 1, 5),
endRangeDate:
rangeDates.lastOrNull ?? DateTime(DateTime.now().year - 1, 7),
headerTitle: const Text('Month Picker Dialog'),
monthPickerDialogSettings: MonthPickerDialogSettings(
dialogSettings: PickerDialogSettings(
Expand Down Expand Up @@ -199,11 +202,10 @@ class _MyAppState extends State<MyApp> {
),
rangeList: true,
).then((List<DateTime>? dates) {
if (dates != null) {
print(dates);
if (dates.isNotEmpty) {
print(dates.last.lastDayOfMonth());
}
if (dates != null && dates.isNotEmpty) {
setState(() {
rangeDates = dates;
});
}
});
}
Expand Down Expand Up @@ -247,6 +249,16 @@ class _MyAppState extends State<MyApp> {
style: Theme.of(context).textTheme.headlineMedium,
textAlign: TextAlign.center,
),
const SizedBox(
height: 40,
),
Text(
'Selected range: ${rangeDates.map((dateTime) {
return dateTime.toIso8601String().split('T').first;
}).join(', ')}',
style: Theme.of(context).textTheme.headlineMedium,
textAlign: TextAlign.center,
),
],
),
),
Expand Down

0 comments on commit f41bade

Please sign in to comment.