Skip to content

Commit

Permalink
refactor(heat_map_day): use proper ConditionalParentWidget (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 authored Dec 24, 2021
1 parent ce2c24f commit 9c046d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
53 changes: 28 additions & 25 deletions lib/widgets/standalone/heat_map_calendar/heat_map_day.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cabin_booking/widgets/layout/conditional_widget_wrap.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

Expand All @@ -11,7 +12,7 @@ class HeatMapDay extends StatelessWidget {
final Map<int, Color> thresholds;
final Color defaultColor;
final DateTime? date;
final bool messageHidden;
final bool showTooltip;
final void Function(DateTime, int)? onTap;
final String Function(int)? valueWrapper;
final bool highlightToday;
Expand All @@ -25,7 +26,7 @@ class HeatMapDay extends StatelessWidget {
this.thresholds = const {},
this.defaultColor = Colors.black12,
this.date,
this.messageHidden = false,
this.showTooltip = true,
this.onTap,
this.valueWrapper,
this.highlightToday = false,
Expand All @@ -46,32 +47,34 @@ class HeatMapDay extends StatelessWidget {

@override
Widget build(BuildContext context) {
final container = Padding(
padding: EdgeInsets.all(space * 0.5),
child: InkWell(
borderRadius: const BorderRadius.all(Radius.circular(2.0)),
onTap: date == null ? null : () => onTap?.call(date!, value),
child: Container(
height: size,
width: size,
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(2.0)),
color: thresholds.colorFromThreshold(value, defaultColor),
border: containerBorder,
return ConditionalWidgetWrap(
condition: showTooltip,
conditionalBuilder: (child) {
return Tooltip(
verticalOffset: 14.0,
message: [
valueWrapper?.call(value) ?? '$value',
if (date != null) DateFormat.d().add_MMM().add_y().format(date!),
].join(' · '),
child: child,
);
},
child: Padding(
padding: EdgeInsets.all(space * 0.5),
child: InkWell(
borderRadius: const BorderRadius.all(Radius.circular(2.0)),
onTap: date == null ? null : () => onTap?.call(date!, value),
child: Container(
height: size,
width: size,
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(2.0)),
color: thresholds.colorFromThreshold(value, defaultColor),
border: containerBorder,
),
),
),
),
);

return messageHidden
? container
: Tooltip(
verticalOffset: 14.0,
message: [
valueWrapper?.call(value) ?? '$value',
if (date != null) DateFormat.d().add_MMM().add_y().format(date!),
].join(' · '),
child: container,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class HeatMapLegend extends StatelessWidget {
value: color.key,
size: squareSize,
space: space,
messageHidden: true,
showTooltip: false,
thresholds: colorThresholds,
),
SizedBox(width: space),
Expand Down

0 comments on commit 9c046d4

Please sign in to comment.