Flutter日歷組件mini_calendar

mini_calendar

插件地址 https://pub.flutter-io.cn/packages/mini_calendar
GitHub https://github.com/OpenFlutter/mini_calendar

Date component developed with Flutter, plans to support display, swipe left and right, add date mark, radio, display week, etc.

使用Flutter開發(fā)的日期組件,計劃支持顯示,左右滑動,添加日期標(biāo)記,單選,顯示星期等功能。

主要想實現(xiàn)的內(nèi)容

功能設(shè)計

使用

引入庫

dependencies:
  mini_calendar: ^0.3.2

導(dǎo)包

import 'package:mini_calendar/mini_calendar.dart';

月視圖(MonthWidget)

MonthWidget();// 默認(rèn)當(dāng)月
  • 可通過控制器參數(shù)來控制顯示的月份以及選擇的日期
MonthWidget(
  controller: MonthController.init(
      MonthOption<String>(
        currentDay: DateDay.now().copyWith(month: index + 1, day: Random().nextInt(27) + 1),
        currentMonth: DateMonth.now().copyWith(month: index + 1),
      )
  ),
)
  • 支持顯示連選
MonthWidget(
  controller: MonthController.init(MonthOption(
    currentMonth: DateMonth.now().copyWith(month: 1),
    enableContinuous: true,
    firstSelectDay: DateDay.now().copyWith(month: 1, day: 8),
    secondSelectDay: DateDay.now().copyWith(month: 1, day: 18),
  )),
)
  • 支持多選
MonthWidget(
  controller: MonthController.init(MonthOption(
    currentMonth: DateMonth.now().copyWith(month: 1),
    enableMultiple: true,
    multipleDays: [
            DateDay.now().copyWith(month: 1, day: 3),
            DateDay.now().copyWith(month: 1, day: 5),
            DateDay.now().copyWith(month: 1, day: 8),
          ],
  )),
)
  • 支持添加標(biāo)記
  • ……
月視圖

滾動日歷(MonthPageView)

控制器需要創(chuàng)建后獲取 onCreated

MonthPageView(
  padding: EdgeInsets.all(1),
  scrollDirection: Axis.horizontal,// 水平滑動或者豎直滑動
  option: MonthOption(
    enableContinuous: true,// 單選、連選控制
    marks: { 
      DateDay.now().copyWith(day: 1): '111',
      DateDay.now().copyWith(day: 5): '222',
      DateDay.now().copyWith(day: 13): '333',
      DateDay.now().copyWith(day: 19): '444',
      DateDay.now().copyWith(day: 26): '444',
    },
  ),
  showWeekHead: true, // 顯示星期頭部
  onContinuousSelectListen: (firstDay, endFay) {
  },// 連選回調(diào)
  onMonthChange: (month) {
  },// 月份更改回調(diào)
  onDaySelected: (day, data) {
  },// 日期選中會迪歐啊
  onCreated: (controller){
  }, // 控制器回調(diào)
),

控制器

參數(shù)初始化

MonthOption({
    DateDay currentDay,//選擇的日期
    DateMonth currentMonth,//當(dāng)前月份
    int firstWeek = 7,//第一列顯示的星期 [1,7]
    DateDay firstSelectDay,//連選第一個日期
    DateDay secondSelectDay,//連選第二個日期
    bool enableContinuous = false,//是否支持連選
    Map<DateDay, T> marks = const {},//標(biāo)記
    DateDay minDay,//可選的最小日期
    DateDay maxDay,//可選的最大日期
  });

注銷

MonthPageController#dispose();

更新

MonthPageController#reLoad();

下一月

MonthPageController#next();

上一月

MonthPageController#last();

跳轉(zhuǎn)到指定月份

MonthPageController#goto(DateMonth month);
演示

高級功能

自定義

自定義月視圖背景

buildMonthBackground: (_, width, height, month) => Image.network(
    'https://ssyerv1.oss-cn-hangzhou.aliyuncs.com/picture/b0c57bd90abd49d59920924010ab66a9.png!sswm',
    height: height,
    width: width,
    fit: BoxFit.cover,
    ),

自定義月視圖頭部

buildMonthHead: (ctx, width, height, month) => Container(
padding: EdgeInsets.all(5),
child: Row(
  mainAxisAlignment: MainAxisAlignment.start,
  children: <Widget>[
    Text(
      "${month.year}年",
      style: TextStyle(fontSize: 40, color: Colors.white),
    ),
    Container(
      margin: EdgeInsets.only(left: 5, right: 5),
      width: 1,
      color: Colors.yellow,
      height: 50,
    ),
    Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Text(
          "${month.month}月",
          style: TextStyle(fontSize: 18, color: Colors.orange),
        ),
        Text("這是一個自定義的月頭部"),
      ],
    )
  ],
),
),
  • 自定義星期頭部
  • 自定義日視圖
  • ……
自定義背景
自定義背景

更多功能clone項目,運行demo

開源不易,老鐵們多多支持,點個贊也是支持!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容