Skip to content

Commit

Permalink
Support onDayLongPressed as a feature request
Browse files Browse the repository at this point in the history
- Fixes #103.
  • Loading branch information
hyochan committed Sep 14, 2019
1 parent ceb1010 commit 495148f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 48 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## [1.3.21]
+ Support intl >= 0.15.7 < 0.17.0 to inclease `pub` health
+ Removed deprecated methods ~~`markedDates`~~, ~~`markedDateColor`~~
+ Fixes [#101](https://github.com/dooboolab/flutter_calendar_carousel/issues/101)
+ Fixes [#104](https://github.com/dooboolab/flutter_calendar_carousel/issues/104)
+ Fixes [#112](https://github.com/dooboolab/flutter_calendar_carousel/issues/112)
+ Fixes [#119](https://github.com/dooboolab/flutter_calendar_carousel/issues/119)
+ Support long pressed as a feature request[#103](https://github.com/dooboolab/flutter_calendar_carousel/issues/103)
## [1.3.20]
+ Support intl >= 0.15.7
## [1.3.19]
Expand Down
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ class _MyHomePageState extends State<MyHomePage> {
onCalendarChanged: (DateTime date) {
this.setState(() => _currentMonth = DateFormat.yMMM().format(date));
},
onDayLongPressed: (DateTime date) {
print('long pressed date $date');
},
);

return new Scaffold(
Expand Down
106 changes: 58 additions & 48 deletions lib/flutter_calendar_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:intl/intl.dart' show DateFormat;
export 'package:flutter_calendar_carousel/classes/event_list.dart';

typedef MarkedDateIconBuilder<Event> = Widget Function(Event event);
typedef void OnDayLongPressed(DateTime day);

class CalendarCarousel<T> extends StatefulWidget {
final double viewportFraction;
Expand Down Expand Up @@ -88,6 +89,7 @@ class CalendarCarousel<T> extends StatefulWidget {
final bool isScrollable;
final bool showOnlyCurrentMonthDate;
final bool pageSnapping;
final OnDayLongPressed onDayLongPressed;

CalendarCarousel({
this.viewportFraction = 1.0,
Expand Down Expand Up @@ -155,6 +157,7 @@ class CalendarCarousel<T> extends StatefulWidget {
this.isScrollable = true,
this.showOnlyCurrentMonthDate = false,
this.pageSnapping = false,
this.onDayLongPressed,
});

@override
Expand Down Expand Up @@ -351,57 +354,60 @@ class _CalendarState<T> extends State<CalendarCarousel<T>> {
) {
return Container(
margin: EdgeInsets.all(widget.dayPadding),
child: FlatButton(
color:
isSelectedDay && widget.selectedDayButtonColor != null
? widget.selectedDayButtonColor
: isToday && widget.todayButtonColor != null
? widget.todayButtonColor
: widget.dayButtonColor,
onPressed: () => _onDayPressed(now),
padding: EdgeInsets.all(widget.dayPadding),
shape: widget.markedDateCustomShapeBorder != null
&& widget.markedDatesMap != null
&& widget.markedDatesMap.getEvents(now).length > 0
? widget.markedDateCustomShapeBorder
: widget.daysHaveCircularBorder == null
? CircleBorder()
: widget.daysHaveCircularBorder ?? false
? CircleBorder(
side: BorderSide(
color: isSelectedDay
? widget.selectedDayBorderColor
: isToday && widget.todayBorderColor != null
? widget.todayBorderColor
: isPrevMonthDay
? widget.prevMonthDayBorderColor
: isNextMonthDay
? widget.nextMonthDayBorderColor
: widget.thisMonthDayBorderColor,
),
)
: RoundedRectangleBorder(
side: BorderSide(
color: isSelectedDay
child: GestureDetector(
onLongPress: () => _onDayLongPressed(now),
child: FlatButton(
color:
isSelectedDay && widget.selectedDayButtonColor != null
? widget.selectedDayButtonColor
: isToday && widget.todayButtonColor != null
? widget.todayButtonColor
: widget.dayButtonColor,
onPressed: () => _onDayPressed(now),
padding: EdgeInsets.all(widget.dayPadding),
shape: widget.markedDateCustomShapeBorder != null
&& widget.markedDatesMap != null
&& widget.markedDatesMap.getEvents(now).length > 0
? widget.markedDateCustomShapeBorder
: widget.daysHaveCircularBorder == null
? CircleBorder()
: widget.daysHaveCircularBorder ?? false
? CircleBorder(
side: BorderSide(
color: isSelectedDay
? widget.selectedDayBorderColor
: isToday && widget.todayBorderColor != null
? widget.todayBorderColor
: isPrevMonthDay
? widget.prevMonthDayBorderColor
: isNextMonthDay
? widget.nextMonthDayBorderColor
: widget.thisMonthDayBorderColor,
? widget.todayBorderColor
: isPrevMonthDay
? widget.prevMonthDayBorderColor
: isNextMonthDay
? widget.nextMonthDayBorderColor
: widget.thisMonthDayBorderColor,
),
)
: RoundedRectangleBorder(
side: BorderSide(
color: isSelectedDay
? widget.selectedDayBorderColor
: isToday && widget.todayBorderColor != null
? widget.todayBorderColor
: isPrevMonthDay
? widget.prevMonthDayBorderColor
: isNextMonthDay
? widget.nextMonthDayBorderColor
: widget.thisMonthDayBorderColor,
),
),
),
child: Stack(
children: <Widget>[
Center(
child: getDefaultTextStyle(isSelectable, index, isSelectedDay, isToday, isPrevMonthDay, textStyle, defaultTextStyle, isNextMonthDay, isThisMonthDay, now),
),
widget.markedDatesMap != null
? _renderMarkedMapContainer(now)
: Container(),
],
child: Stack(
children: <Widget>[
Center(
child: getDefaultTextStyle(isSelectable, index, isSelectedDay, isToday, isPrevMonthDay, textStyle, defaultTextStyle, isNextMonthDay, isThisMonthDay, now),
),
widget.markedDatesMap != null
? _renderMarkedMapContainer(now)
: Container(),
],
),
),
),
);
Expand Down Expand Up @@ -614,6 +620,10 @@ class _CalendarState<T> extends State<CalendarCarousel<T>> {
.toList();
}

void _onDayLongPressed(DateTime picked) {
widget.onDayLongPressed(picked);
}

void _onDayPressed(DateTime picked) {
if (picked == null) return;
if (widget.minSelectedDate != null &&
Expand Down

0 comments on commit 495148f

Please sign in to comment.