[英]How to add holidays in flutter table calendar
I am going to develop a holiday app in flutter using table calendar package.how can i add only special holidays in to calender.In my code every month 20 show as selected date.i want to select specific holiday in all the months.how can i do this.我打算使用表格日历包在 flutter 中开发一个假期应用程序。我怎样才能将特殊假期添加到日历中。在我的代码中,每个月 20 显示为选定日期。我想在所有月份中选择特定假期。如何我这样做。
develop holiday calender using flutter使用 flutter 开发假日日历
my code is below.我的代码在下面。
import 'package:flutter/material.dart';
import 'package:table_calendar/table_calendar.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: TableCalendar(
firstDay: DateTime.utc(2010, 01, 01),
lastDay: DateTime.utc(2030, 12, 31),
focusedDay: DateTime.now(),
holidayPredicate: (day) {
// Every 20th day of the month will be treated as a holiday
return day.day == 20;
},
selectedDayPredicate: (day) {
return isSameDay(_selectedDay, day);
},
onDaySelected: (selectedDay, focusedDay) {
setState(() {
_selectedDay = selectedDay;
});
},
),
),
);
}
}
You can set any function there:您可以在那里设置任何功能:
holidayPredicate: (day) {
// Weekends
return day.weekday >= 6;
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.