Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Row(
highlightColor: Colors.lightGreen,
onPressed: () {
setState(() {
_controller.backward();
_controller.backward!();
});
},
)),
Expand All @@ -64,7 +64,7 @@ Row(
highlightColor: Colors.lightGreen,
onPressed: () {
setState(() {
_controller.forward();
_controller.forward!();
});
},
)),
Expand Down Expand Up @@ -104,13 +104,13 @@ Using the `onViewChanged` callback of the date picker, you can get the mid date

```xml
void viewChanged(DateRangePickerViewChangedArgs args) {
_startDate = (args.visibleDateRange.startDate
.difference(args.visibleDateRange.endDate)
.inDays);
var middleDate = (_startDate ~/ 2).toInt();
midDate = args.visibleDateRange.startDate.add(Duration(days: middleDate));
final DateTime visibleStartDate = args.visibleDateRange.startDate!;
final DateTime visibleEndDate = args.visibleDateRange.endDate!;
final int totalVisibleDays = (visibleStartDate.difference(visibleEndDate).inDays);
final DateTime midDate =
visibleStartDate.add(Duration(days: totalVisibleDays ~/ 2));
headerString = DateFormat('MMMM yyyy').format(midDate).toString();
SchedulerBinding.instance.addPostFrameCallback((duration) {
SchedulerBinding.instance!.addPostFrameCallback((duration) {
setState(() {});
});
}
Expand Down
50 changes: 16 additions & 34 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,17 @@ class HeaderCustomization extends StatefulWidget {
}

class _HeaderCustomizationState extends State<HeaderCustomization> {
DateRangePickerController _controller;
int _startDate;
String headerString;
DateTime midDate;
double width, cellWidth, height, cellHeight;

@override
void initState() {
// TODO: implement initState
_controller = DateRangePickerController();
_startDate = 0;
width = 0.0;
cellWidth = 0.0;
height = 0.0;
cellHeight = 0.0;
midDate = DateTime.now();
headerString = '';
super.initState();
}
final DateRangePickerController _controller = DateRangePickerController();
String headerString = '';

@override
Widget build(BuildContext context) {
width = MediaQuery.of(context).size.width;
cellWidth = width / 9;
height = MediaQuery.of(context).size.height;
cellHeight = height / 17;
final double width = MediaQuery.of(context).size.width;
final double cellWidth = width / 9;

return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
children: <Widget>[
Expand All @@ -71,7 +52,7 @@ class _HeaderCustomizationState extends State<HeaderCustomization> {
highlightColor: Colors.lightGreen,
onPressed: () {
setState(() {
_controller.backward();
_controller.backward!();
});
},
)),
Expand All @@ -94,7 +75,7 @@ class _HeaderCustomizationState extends State<HeaderCustomization> {
highlightColor: Colors.lightGreen,
onPressed: () {
setState(() {
_controller.forward();
_controller.forward!();
});
},
)),
Expand All @@ -118,22 +99,23 @@ class _HeaderCustomizationState extends State<HeaderCustomization> {
monthCellStyle: DateRangePickerMonthCellStyle(
cellDecoration: BoxDecoration(color: Color(0xFF6fb98f)),
leadingDatesDecoration:
BoxDecoration(color: Color(0xFF6fb98f)),
BoxDecoration(color: Color(0xFF6fb98f)),
trailingDatesDecoration:
BoxDecoration(color: Color(0xFF6fb98f)))),
BoxDecoration(color: Color(0xFF6fb98f)))),
)
],
));
}

void viewChanged(DateRangePickerViewChangedArgs args) {
_startDate = (args.visibleDateRange.startDate
.difference(args.visibleDateRange.endDate)
.inDays);
var middleDate = (_startDate ~/ 2).toInt();
midDate = args.visibleDateRange.startDate.add(Duration(days: middleDate));
final DateTime visibleStartDate = args.visibleDateRange.startDate!;
final DateTime visibleEndDate = args.visibleDateRange.endDate!;
final int totalVisibleDays =
(visibleStartDate.difference(visibleEndDate).inDays);
final DateTime midDate =
visibleStartDate.add(Duration(days: totalVisibleDays ~/ 2));
headerString = DateFormat('MMMM yyyy').format(midDate).toString();
SchedulerBinding.instance.addPostFrameCallback((duration) {
SchedulerBinding.instance!.addPostFrameCallback((duration) {
setState(() {});
});
}
Expand Down
Loading