defaultBuildDayItem<T> function
Widget
defaultBuildDayItem<T>(
- BuildContext context,
- DateDay dayTime, {
- bool enableSelect = false,
- bool hasMark = false,
- double height = 30,
- double width = 30,
- T? markData,
- Color weekColor = const Color(0xa6000000),
- Color weekendColor = const Color(0xffFF4081),
- bool isSelected = false,
- bool isContinuous = false,
- bool isMultiple = false,
- bool first = true,
- bool end = true,
- BuildMark<
T> ? buildMark, - OnDaySelected<
T> ? onDaySelected, - CalendarLocaleType localeType = CalendarLocaleType.zh,
默认构建日视图
context
- 上下文
height
- 控件高
width
- 控件宽
dayTime
- 当前日期
enableSelect
- 是否可选
hasMark
- 是否含有标记
markData
- 标记内容
weekColor
- 工作日颜色
weekendColor
- 周末颜色
isSelected
- 是否被单选
isContinuous
- 是否被连选
isMultiple
- 是否被多选
buildMark
- 自定义构建mark
onDaySelected
- 选择事件
Implementation
Widget defaultBuildDayItem<T>(BuildContext context, DateDay dayTime,
{bool enableSelect = false,
bool hasMark = false,
double height = 30,
double width = 30,
T? markData,
Color weekColor = const Color(0xa6000000),
Color weekendColor = const Color(0xffFF4081),
bool isSelected = false,
bool isContinuous = false,
bool isMultiple = false,
bool first = true,
bool end = true,
BuildMark<T>? buildMark,
OnDaySelected<T>? onDaySelected,
CalendarLocaleType localeType = CalendarLocaleType.zh}) {
Color _sideColor = Colors.transparent;
BorderRadiusGeometry borderRadius = BorderRadius.zero;
Color _dayColor = Colors.transparent;
TextStyle _style;
if (!enableSelect) {
_style = TextStyle(
fontSize: 18,
color: dayTime.weekday > 5
? weekendColor.withAlpha(65)
: weekColor.withAlpha(80));
} else {
_style = TextStyle(
fontSize: 18, color: dayTime.weekday > 5 ? weekendColor : weekColor);
}
if (isSelected) {
_dayColor = Color(0xff487cff);
borderRadius = BorderRadius.circular(5);
_style = _style.copyWith(color: Colors.white);
}
if (isMultiple) {
borderRadius = BorderRadius.circular(5);
_sideColor = Colors.deepOrange;
}
if (isContinuous) {
_dayColor = Color(0x99c9d8ff);
if (end) {
_dayColor = Color(0xd9487cff);
_style = _style.copyWith(color: Colors.white);
}
borderRadius = BorderRadius.only(
topLeft: Radius.circular(first ? 5 : 0),
bottomLeft: Radius.circular(first ? 5 : 0),
topRight: Radius.circular(end ? 5 : 0),
bottomRight: Radius.circular(end ? 5 : 0),
);
_sideColor = Color(0xc9c9d8ff);
}
List<Widget> items = [
Center(child: Text("${dayTime.day}${hasMark ? '' : ''}", style: _style))
];
if (dayTime.isToday()) {
items.add(Positioned(
top: 2,
right: 2,
child: Material(
color: Colors.transparent,
shape: RoundedRectangleBorder(
side: BorderSide(width: 0.3, color: Colors.pinkAccent)),
child: Padding(
padding: EdgeInsets.all(1),
child: Text(i18nObjInLocal(localeType)['today'],
style: _style.copyWith(fontSize: 10, color: Colors.pinkAccent)),
),
),
));
}
if (hasMark) {
items.add(buildMark == null
? defaultBuildMark()
: buildMark(context, dayTime, markData));
}
return Padding(
padding: EdgeInsets.only(
top: 9, bottom: 9, left: isMultiple ? 3 : 0, right: isMultiple ? 3 : 0),
child: Material(
color: _dayColor,
shape: RoundedRectangleBorder(
borderRadius: borderRadius,
side: BorderSide(
width: 0.5,
color: _sideColor,
),
),
child: Ink(
child: InkWell(
onTap: () {
if (onDaySelected != null) {
onDaySelected(dayTime, markData, enableSelect);
}
},
child: Container(
height: height - 18,
width: width - (isMultiple ? 6 : 0),
child: Stack(children: items),
),
),
),
),
);
}