Last active
November 10, 2022 06:17
-
-
Save harsh1772/45f150f1ba650a52b7ceaf3ce0c7cdfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pacakage: intl: ^0.17.0 | |
pacakage: syncfusion_flutter_datepicker: ^20.3.49 | |
String _selectedDate = ''; | |
String _dateCount = ''; | |
String _range = ''; | |
String _rangeCount = ''; | |
DateRangePickerController dateRangePickerController = | |
DateRangePickerController(); | |
void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) { | |
setState(() { | |
if (args.value is PickerDateRange) { | |
_range = '${DateFormat('dd/MM/yyyy').format(args.value.startDate)} -'; | |
// ignore: lines_longer_than_80_chars | |
' ${DateFormat('dd/MM/yyyy').format(args.value.endDate ?? args.value.startDate)}'; | |
Navigator.pop(context); | |
} else if (args.value is DateTime) { | |
_selectedDate = args.value.toString(); | |
var date = DateTime.parse(_selectedDate).toLocal(); | |
var inputFormat = DateFormat('yyyy-MM-dd HH:mm'); | |
var inputDate = | |
inputFormat.parse(date.toString()); // <-- dd/MM 24H format | |
///if 25/11/2020 12:00 AM show then write('dd/MM/YYYY hh:mm a') | |
// var outputFormat = DateFormat('dd/MM/yyyy hh:mm a'); | |
var outputFormat = DateFormat('dd MMM, '); | |
var outputDate = outputFormat.format(inputDate); | |
var outputFormatDay = DateFormat.E().format(inputDate); | |
// print(outputDate); | |
// print(outputFormatDate); | |
OUTPUT::--- 18 Jan, Wed | |
_datePickController.text = outputDate + outputFormatDay; | |
Navigator.pop(context); | |
} else if (args.value is List<DateTime>) { | |
_dateCount = args.value.length.toString(); | |
Navigator.pop(context); | |
} else { | |
_rangeCount = args.value.length.toString(); | |
Navigator.pop(context); | |
} | |
}); | |
} | |
------------------------------------------------------------------------------------------------------------------------------- | |
SfDateRangePicker( | |
onSelectionChanged: _onSelectionChanged, | |
controller: dateRangePickerController, | |
selectionMode: DateRangePickerSelectionMode.single, | |
initialDisplayDate: DateTime.now(), | |
navigationMode: DateRangePickerNavigationMode.snap, | |
selectionColor: ColorUtils.secondaryColor, | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment