我正在使用 SFCalendar
我有一个包含约会的日历,我想在
onTap
上仅选择约会,而不能选择单元格。
我也做过类似的事:
SfCalendar(
//...
selectionDecoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(
color: Theme.of(context).colorScheme.primary,
width: 2),
borderRadius:
const BorderRadius.all(Radius.circular(4)),
shape: BoxShape.rectangle,
),
controller: _calendarController,
onTap: (details) {
if (details.targetElement !=
CalendarElement.appointment) {
_calendarController.selectedDate = null;
return;
}
// My selection code here
},
但是看起来太复杂了。
有没有更简单的方法?
非常感谢您抽出时间🙏
试试这个方法-
SfCalendar(
// ...
selectionDecoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(
color: Theme.of(context).colorScheme.primary,
width: 2,
),
borderRadius: const BorderRadius.all(Radius.circular(4)),
shape: BoxShape.rectangle,
),
controller: _calendarController,
onLongPress: (details) {
if (details.targetElement == CalendarElement.appointment) {
// Your selection code here
}
},
)
通过使用 onLongPress,您可以确保在检测到长按时只能选择约会,这可能会提供更流畅的用户体验。