Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OnDateClicked to calendar. Triggers when date boxes clicked #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.packages
.pub/
build/
.idea/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock

Expand Down
7 changes: 6 additions & 1 deletion lib/heatmap_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class HeatMapCalendar extends StatefulWidget {
/// Helps avoiding overspacing issues
final double safetyMargin;

// Callback for when a user clicks on date box
final void Function(DateTime) OnDateClicked;

const HeatMapCalendar(
{Key key,
@required this.input,
Expand All @@ -52,7 +55,8 @@ class HeatMapCalendar extends StatefulWidget {
this.textOpacity: 0.2,
this.labelTextColor: Colors.black,
this.dayTextColor: Colors.black,
this.safetyMargin: 0})
this.safetyMargin: 0,
this.OnDateClicked})
: super(key: key);

@override
Expand Down Expand Up @@ -111,6 +115,7 @@ class HeatMapCalendarState extends State<HeatMapCalendar> {
dayTextColor: widget.dayTextColor,
columnsToCreate: getColumnsToCreate(constraints.maxWidth) - 1,
date: DateTime.now(),
OnDateClicked: (date) => widget.OnDateClicked(date),
)
],
),
Expand Down
31 changes: 18 additions & 13 deletions lib/heatmap_day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class HeatMapDay extends StatelessWidget {
final Duration animationDuration;
final Color textColor;
final FontWeight fontWeight;
final VoidCallback OnDateClicked;

const HeatMapDay(
{Key key,
Expand All @@ -21,7 +22,8 @@ class HeatMapDay extends StatelessWidget {
this.opacity: 0.3,
this.animationDuration: const Duration(milliseconds: 300),
this.textColor: Colors.black,
this.fontWeight})
this.fontWeight,
this.OnDateClicked})
: super(key: key);

/// Loop for getting the right color based on [thresholds] values
Expand All @@ -43,18 +45,21 @@ class HeatMapDay extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
height: size,
width: size,
color: getColorFromThreshold(),
margin: EdgeInsets.all(2.0),
child: AnimatedOpacity(
opacity: opacity,
duration: animationDuration,
child: Text(
currentDay.toString(),
style: TextStyle(fontWeight: fontWeight, color: textColor),
return InkWell(
onTap: () => OnDateClicked(),
child: Container(
alignment: Alignment.center,
height: size,
width: size,
color: getColorFromThreshold(),
margin: EdgeInsets.all(2.0),
child: AnimatedOpacity(
opacity: opacity,
duration: animationDuration,
child: Text(
currentDay.toString(),
style: TextStyle(fontWeight: fontWeight, color: textColor),
),
),
),
);
Expand Down
6 changes: 5 additions & 1 deletion lib/week_columns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class WeekColumns extends StatelessWidget {

final DateTime date;

final void Function(DateTime) OnDateClicked;

const WeekColumns(
{Key key,
@required this.squareSize,
Expand All @@ -32,7 +34,8 @@ class WeekColumns extends StatelessWidget {
@required this.monthLabels,
@required this.dayTextColor,
@required this.columnsToCreate,
@required this.date})
@required this.date,
this.OnDateClicked})
: super(key: key);

/// The main logic for generating a list of columns representing a week
Expand Down Expand Up @@ -80,6 +83,7 @@ class WeekColumns extends StatelessWidget {
currentDay: currentDate.day,
opacity: currentOpacity,
textColor: dayTextColor,
OnDateClicked: () => OnDateClicked(currentDate),
);
columnItems.add(heatMapDay);

Expand Down