一个适用于 Android 和 iOS 的时间调度器,您可以通过单击单元格来创建事件,编辑(更新)和删除您创建的事件。您可以为事件分配颜色,如果事件名称过长,可以通过长按事件来查看完整名称和描述。

特点

入门

flutter pub add time_scheduler_table

用法

为事件添加和事件更新警报定义一个 TextEditingController

TextEditingController textController = TextEditingController();

创建具有标题、日期索引、时间和颜色的事件模型列表。日期索引指定顶部标题(周一、周二或 Day1、Day2)中元素的索引。它从 0 开始

List<EventModel> eventList = [
  EventModel(title: "Math", dayIndex: 0, time: "08:00 - 09:00", color: Colors.orange), // time format :  08:00 - 09:00
  EventModel(title: "History", dayIndex: 1, time: "11:00 - 12:00", color: Colors.pink), // dayIndex is topTitle's index (Monday : 0  or  Day1 : 0)
  EventModel(title: "Guitar & Piano Course", dayIndex: 4, time: "14:00 - 15:00", color: Colors.green),
  EventModel(title: "Meeting", dayIndex: 3, time: "06:00 - 07:00", color: Colors.deepPurple),
  EventModel(title: "Guitar and Piano Course", dayIndex: 2, time: "15:00 - 16:00", color: Colors.blue)
];

创建您的时间调度器小部件

TimeSchedulerTable(
  cellHeight: 48,
  cellWidth: 64,
  topTitles: const ["Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"],      // topTitles is growable : you can add as much as you want
  currentTitleIndex: DateTime.now().weekday - 1,
  // topTitles: const ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"],
  // currentTitleIndex: 2,      --> if currentTitleIndex is 2 then selected day is 3.
  title: "Event Schedule",
  titleStyle: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.black),
  eventTitleStyle: const TextStyle(color: Colors.white, fontSize: 8),
  isBack: false, // back button
  eventList: eventList,
  eventAlert: EventAlert(
    alertTextController: textController,
    borderRadius: const BorderRadius.all(
      Radius.circular(12.0),
      ),
  addAlertTitle: "Add Event",
  editAlertTitle: "Edit",
  addButtonTitle: "ADD",
  deleteButtonTitle: "DELETE",
  updateButtonTitle: "UPDATE",
  hintText: "Event Name",
  textFieldEmptyValidateMessage: "Cannot be empty!",
  addOnPressed: (event) {}, // when an event added to your list
  updateOnPressed: (event) {}, // when an event updated from your list
  deleteOnPressed: (event) {}, // when an event deleted from your list
  ),
),

topTitles 包含您定义的日期或值。它是可选的。默认值为

["Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"]

您可以这样定义:

topTitles: const ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"],
currentTitleIndex: 2,

如果像这样定义,topTitles 将包含从 1 到 14 的数字。如果 currentTitleIndex 是 2,则选定的日期是 3。

GitHub

查看 Github