-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathcalendar_tile.dart
More file actions
69 lines (65 loc) · 1.69 KB
/
calendar_tile.dart
File metadata and controls
69 lines (65 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import 'package:flutter/material.dart';
import 'package:date_utils/date_utils.dart' as dt;
class CalendarTile extends StatelessWidget {
final VoidCallback onDateSelected;
final DateTime date;
final String dayOfWeek;
final bool isDayOfWeek;
final bool isSelected;
final TextStyle dayOfWeekStyles;
final TextStyle dateStyles;
final Widget child;
CalendarTile({
this.onDateSelected,
this.date,
this.child,
this.dateStyles,
this.dayOfWeek,
this.dayOfWeekStyles,
this.isDayOfWeek: false,
this.isSelected: false,
});
Widget renderDateOrDayOfWeek(BuildContext context) {
if (isDayOfWeek) {
return new InkWell(
child: new Container(
alignment: Alignment.center,
child: new Text(
dayOfWeek,
style: dayOfWeekStyles,
),
),
);
} else {
return new InkWell(
onTap: onDateSelected,
child: new Container(
decoration: isSelected
? new BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).primaryColor,
)
: new BoxDecoration(),
alignment: Alignment.center,
child: new Text(
dt.DateUtils.formatDay(date).toString(),
style: isSelected ? Theme.of(context).primaryTextTheme.bodyText1 : dateStyles,
textAlign: TextAlign.center,
),
),
);
}
}
@override
Widget build(BuildContext context) {
if (child != null) {
return new InkWell(
child: child,
onTap: onDateSelected,
);
}
return new Container(
child: renderDateOrDayOfWeek(context),
);
}
}