Flutter 之 table_calendar 控件

1.库导入

在pubspec.yaml文件中

dev_dependencies:

table_calendar: ^3.2.0

  1. 代码编写
Kotlin 复制代码
TableCalendar(
  daysOfWeekHeight: 20,
  availableGestures: AvailableGestures.horizontalSwipe,
  firstDay:  DateTime.now().subtract(const Duration(days: 365)),
  lastDay:  DateTime.now(),
  calendarBuilders: CalendarBuilders(

    markerBuilder: (context, day, events) {
      bool isMarker = false;
      for(int i in entries){
        if(day.day == i){
          isMarker = true;
          break;
        }
      }
      if(isMarker){
        return Positioned(
            right: 0,
            top: 0,
            child: Container(
              padding: const EdgeInsets.all(4),
              decoration: BoxDecoration(
                color: Colors.red,
                shape: BoxShape.circle,
              ),
            )
        );
      } else {
        return null;
      }

    }

  ),
  focusedDay: _focusedDay,
  onDaySelected: (selectedDay, focusedDay) {
    setState(() {
      _selectedDay = selectedDay;
      _focusedDay = focusedDay;
    });
  },
  onFormatChanged: (format) {
    setState(() {
      _calendarFormat = format;
    });
  },
  calendarStyle: const CalendarStyle(
    selectedDecoration: BoxDecoration(
      color: Colors.blue,
      shape: BoxShape.circle,
    ),
    todayDecoration: BoxDecoration(
      color: Color(0xFFBBDEFB),
      shape: BoxShape.circle,
    ),
    markersMaxCount: 1,
    isTodayHighlighted: false,
  ),
  headerStyle: const HeaderStyle(
    titleCentered: true,
    formatButtonVisible: false,
  ),
)

3.效果图

相关推荐
恋猫de小郭1 小时前
2026,Android Compose 终于支持 Hot Reload 了,但是收费
android·前端·flutter
ljt272496066120 小时前
Flutter笔记--事件处理
笔记·flutter
Feng-licong1 天前
告别手写 UI:当 Google Stitch 遇上 Flutter,2026 年的“Vibe Coding”开发流
flutter·ui
不爱吃糖的程序媛1 天前
Flutter OH Engine构建指导
flutter
小蜜蜂嗡嗡2 天前
flutter实现付费解锁内容的遮挡
android·flutter
tangweiguo030519872 天前
Flutter iOS 调试利器:idevicesyslog 从入门到精通
flutter
tangweiguo030519872 天前
Flutter 异常捕获与处理:从入门到生产实践
flutter
不爱吃糖的程序媛2 天前
已有 Flutter 应用适配鸿蒙平台指导文档
flutter·华为·harmonyos
weixin_443478512 天前
flutter组件学习之卡片与列表
javascript·学习·flutter
不爱吃糖的程序媛2 天前
Flutter-OH 升级指导
flutter