【问题标题】:How to add holidays in flutter table calendar如何在颤振表日历中添加假期
【发布时间】:2022-12-21 09:54:31
【问题描述】:

我打算使用 table calendar package 在 flutter 中开发一个假期应用程序。我怎样才能将特殊假期添加到日历中。在我的代码中,每个月 20 显示为选定日期。我想在所有月份中选择特定的假期。怎么能我这样做。

使用 flutter 开发假期日历

我的代码在下面。

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;
            });
          },
        ),
      ),
    );
  }
}

【问题讨论】:

  • 在显示您最大努力的代码中添加一个特定问题。
  • 请避免像这样的问题“我需要用 flutter 代码完整回答”。每个人都在这里互相帮助。您必须首先展示您的工作并发布您的代码,以便其他人可以重现您面临的相同问题。

标签: flutter table-calendar


【解决方案1】:

您可以在那里设置任何功能:

holidayPredicate: (day) {
          // Weekends
          return day.weekday >= 6;
        },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 2020-05-14
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多