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.效果图

相关推荐
忆江南9 小时前
iOS 深度解析
flutter·ios
明君879979 小时前
Flutter 实现 AI 聊天页面 —— 记一次 Markdown 数学公式显示的踩坑之旅
前端·flutter
恋猫de小郭10 小时前
移动端开发稳了?AI 目前还无法取代客户端开发,小红书的论文告诉你数据
前端·flutter·ai编程
MakeZero13 小时前
Flutter那些事-交互式组件
flutter
shankss13 小时前
pull_to_refresh_simple
flutter
shankss13 小时前
Flutter 下拉刷新库新特性:智能预加载 (enableSmartPreload) 详解
flutter
SoaringHeart2 天前
Flutter调试组件:打印任意组件尺寸位置信息 NRenderBox
前端·flutter
九狼2 天前
Flutter URL Scheme 跨平台跳转
人工智能·flutter·github
_squirrel2 天前
记录一次 Flutter 升级遇到的问题
flutter
Haha_bj3 天前
Flutter——状态管理 Provider 详解
flutter·app