From f41bade61aecb53edd533528a17fe251f1489141 Mon Sep 17 00:00:00 2001 From: Gianluca Bettega Date: Mon, 16 Dec 2024 15:14:39 -0300 Subject: [PATCH] improve sample --- example/lib/main.dart | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 2c8d07c..5668a3c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -52,6 +52,7 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { DateTime? selectedDate; int? selectedYear; + List rangeDates = []; @override void initState() { @@ -144,8 +145,10 @@ class _MyAppState extends State { 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( @@ -199,11 +202,10 @@ class _MyAppState extends State { ), rangeList: true, ).then((List? dates) { - if (dates != null) { - print(dates); - if (dates.isNotEmpty) { - print(dates.last.lastDayOfMonth()); - } + if (dates != null && dates.isNotEmpty) { + setState(() { + rangeDates = dates; + }); } }); } @@ -247,6 +249,16 @@ class _MyAppState extends State { 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, + ), ], ), ),