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

相关推荐
陆断枫15 小时前
Flutter 3.47 动画引擎盘点:Impeller 全平台,和那些"新特性"
flutter
程序员老刘16 小时前
Flet 1.0 思路很好,可惜来晚了
flutter·ai编程·客户端
m0_738185821 天前
Flutter 鸿蒙化实战:qr_code_scanner_plus 适配 OpenHarmony,二维码扫描
flutter·华为·harmonyos·鸿蒙
恋猫de小郭1 天前
Flutter + EmbeddingGemma 2,谷歌发布完全端侧的 AI Edge Foresight
android·前端·flutter
君赏2 天前
基于 FlutterPatch 快速接入 Flutter 热更新
flutter
律宏阔2 天前
Dart FFI 内存管理:用 using + Arena 替代嵌套 try-finally
前端·flutter
律宏阔2 天前
Flutter 调用 Go:从 c-shared + ffigen 到 @Native + Native Assets 踩坑记录
前端·flutter
律宏阔2 天前
Dart FFI 回调无法使用局部变量?使用 NativeCallable.isolateLocal
前端·flutter
天空之城--2 天前
Android一周动态:AI编程、Compose与车载生态新信号
android·flutter
码林鼠2 天前
Flutter之Widget/State 入门文档
flutter